如果表中有期望值,那么我想使用Selenium WebDriver选择该行的第0个索引中存在的超链接 [英] If there is a expected value in the table then I want to select the hyperlink that exists in 0th index of the row using Selenium WebDriver
本文介绍了如果表中有期望值,那么我想使用Selenium WebDriver选择该行的第0个索引中存在的超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网页中有一张表格,如下图所示.如果我的期望值在该特定行中,我想选择在表行的第0个索引中存在的超链接.
I have a table in my webpage as attached in the diagram attached. I want to select the Hyperlink existing in 0th index of the table row if my expected value is there in that particular row.
如何使用Java在Selenium WebDriver中实现呢? 在此处输入图片描述
How can I implement this in Selenium WebDriver using Java? enter image description here
推荐答案
您可以尝试以下代码:
List <WebElement> rowElements = driver.findElements(By.xpath("\\table\\tr"));
for(int i=1; i< rowElements.size(); i++){
List <WebElement> colElements = rowElements.get(i).findElements(By.tagName("td"));
for(int j=1; j<colElements.getSize(); j++){
if(colElements.get(j).getText().equals("yourValue")){ //yourValue is value to be matched in column 3
colElements.get(0).click();
//clicking the hyperlink
}
}
}
这篇关于如果表中有期望值,那么我想使用Selenium WebDriver选择该行的第0个索引中存在的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文