![](/img/trans.png)
[英]Unable to perform Drag and Drop in Selenium Web-Driver using Java
[英]On html, data in table form, how i click and print data on 2nd position using selenium web-driver java
我如何單擊鏈接並使用Selenium WebDriver打印數據。 在這里,我想單擊鏈接Yahoo.com,並要打印“ Yahoo”,也要在“ Yahoo的搜索數據”中打印數據。這里,鏈接和可打印數據以及鏈接是動態的。 那么我如何使用Java語言中的Selenium Webdriver來完成這些操作
<table>
<tbody>
<tr>
<td>
<span>
<a href="www.google.com">Google</a>
</span>
</td>
<td>
<span>Searched data on Google</span>
</td>
</tr>
<tr>
<td>
<span>
<a href="www.yahoo.com">Yahoo</a>
</span>
</td>
<td>
<span>Searched data on Yahoo</span>
</td>
</tr>
</tr>
</tbody>
</table>
試用以下代碼:
void linkToClick(str linkName) {
WebElement link = driver.findElement(By.xpath("//table//a[contains(.,'" + linkName + "')]")); // finding link with desired name like yahoo or google
WebElement data = driver.findElement(By.xpath("//table//a[contains(.,'" + linkName + "')]/ancestor::td/following-sibling::td/span")); // finding text in the span next to provided link
System.out.println(data.getText()); // printing text in span
link.click(); // clicking link
}
希望這是你在尋找...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.