0

HTMLは次のとおりです。

<table class="wikitable openei-infobox">

    <tbody><tr>
    <th> <a href="/wiki/Property:Name" title="Property:Name">Name</a>
    </th>
    <td> Ambit Energy, L.P.
    <pre style="display: none;"></pre>
    </td></tr>
    <tr>
    <th> <a href="/wiki/Property:Place" title="Property:Place">Place</a>
    </th>
    <td> <a href="/wiki/Maryland" title="Maryland">Maryland</a>
    <pre style="display: none;"></pre>
    ......

Selenium を使用して要素Marylandを見つける必要がありますが、安定していないため、次のように xpath を使用("//a[@href='...']")できず、どちらも使用できません。By.linkText私は次のことを試しました:

String el = driver.findElement(By.xpath(("//table[@class='wikitable openei-infobox']/td[1]"))).get(1).getText();
        System.out.println(el);

私のコードで何が間違っていますか?

4

1 に答える 1