如何点击与硒的链接webdriver的

如何点击与硒的链接webdriver的

问题描述:

如何点击与具有相同名称如何点击与硒的链接webdriver的

硒的webdriver链接
driver.findElement(By.linkText("View All")).click(); 

还有一些其他的链接也有像View All

+0

可以请你发布的HTML代码示例? –

+0

你提到你有多个“查看全部”链接ryt?它们存在于具有不同用户名的任何表中吗? –

+0

这两个小部件是否有不同的类名或任何不同的属性?请发布这两个小部件的HTML代码。这将帮助我们为您提供一些可靠的解决方案 –

你应该尝试找到名称相同与如类名和文本链接的其他属性的组合,唯一的链接通过如下使用xpath: -

WebDriverWait wait = new WebDriverWait(driver, 10); 
WebElement link = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//a[contains(@class, 'absence-viewall') and contains(text(), 'View All')]"))); 
link.click(); 

还是我F该环节具有独特的类名,最好的办法如下使用By.cssSelector(): -

WebDriverWait wait = new WebDriverWait(driver, 10); 
WebElement link = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("a.absence-viewall"))); 
link.click();