使用Selenium Java从网页中查找链接
我正在kelenium java工作。我编写了用于Google搜索的自动化测试的Java代码,并且需求是从网页中查找链接,该链接被列入Excel表格,然后在网页上单击该链接。因此,我从网页中获取了所有链接,但无法单击Excel表的链接。 。
List<WebElement> allLinks = driver.findElements(By.tagName("a"));
int linkcount=allLinks.size();
System.out.println("All Links :" +linkcount);
for(int j=0 ;j<linkcount;j++ )
{
String ele= driver.findElements(By.tagName("a")).get(j).getText();
System.out.println(ele);
if(ele.equals(Expected))
{
allLinks.get(j).click();
}
I am working on selenium java. I wrote java code for Automation testing for google search and requirement is find link from webpage that is given into excel sheet and click on that link on webpage.so i am getting all links from webpage but not able to click on provided link from excel sheet.
List<WebElement> allLinks = driver.findElements(By.tagName("a"));
int linkcount=allLinks.size();
System.out.println("All Links :" +linkcount);
for(int j=0 ;j<linkcount;j++ )
{
String ele= driver.findElements(By.tagName("a")).get(j).getText();
System.out.println(ele);
if(ele.equals(Expected))
{
allLinks.get(j).click();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下代码应起作用,请确保字符串等于条件正在评估为true或不,是否可能有预期的URL字符串中的空间,这可能导致条件评估为false
Following code should work , make sure that String equals condition is evaluating to true or not there might be spaces in the Expected URL String which may lead to condition evaluating to false