Java 如何使用Selenium定位不稳定的表元素?
以下是HTML: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:
<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);