2016-08-25 46 views
0

如何點擊與具有相同名稱如何點擊與硒的鏈接webdriver的

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

還有一些其他的鏈接也有像View All

+0

可以請你發佈的HTML代碼示例? –

+0

你提到你有多個「查看全部」鏈接ryt?它們存在於具有不同用戶名的任何表中嗎? –

+0

這兩個小部件是否有不同的類名或任何不同的屬性?請發佈這兩個小部件的HTML代碼。這將幫助我們爲您提供一些可靠的解決方案 –

回答

2

你應該嘗試找到名稱相同與如類名和文本鏈接的其他屬性的組合,唯一的鏈接通過如下使用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(); 
相關問題