Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Selenium定位不稳定的表元素?_Java_Selenium_Html Table - Fatal编程技术网

Java 如何使用Selenium定位不稳定的表元素?

Java 如何使用Selenium定位不稳定的表元素?,java,selenium,html-table,Java,Selenium,Html Table,以下是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:

以下是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>
    ......
我的代码有什么问题?

请尝试以下操作: 字符串el=driver.findElement(By.xpath(“//tr[2]/td[1]”)).getText(); 系统输出打印项次(el)

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