单击超链接时出现Selenium webdriver问题
尝试使用Selenium Web驱动程序单击超链接时遇到问题。我尝试使用选择器和xPath,但似乎没有任何效果。我所要做的就是点击超链接单击超链接时出现Selenium webdriver问题,selenium,selenium-webdriver,xpath,css-selectors,webdriverwait,Selenium,Selenium Webdriver,Xpath,Css Selectors,Webdriverwait,尝试使用Selenium Web驱动程序单击超链接时遇到问题。我尝试使用选择器和xPath,但似乎没有任何效果。我所要做的就是点击超链接 <a href="JavaScript:void(0)" id="id_34" alt="Title: Pending Changes-type: Web Intelligence-owner: Administrator-last viewed time: Nov 21, 2018 11:03 AM">Pending Changes</a&
<a href="JavaScript:void(0)" id="id_34" alt="Title: Pending Changes-type: Web Intelligence-owner: Administrator-last viewed time: Nov 21, 2018 11:03 AM">Pending Changes</a>
Java:
driver.findElement(By.linkText("Pending Changes")).click();
或
该元素为enabled元素,因此您需要引导WebDriverWait使该元素可单击,并且您可以使用以下任一解决方案:
- Java解决方案:
:linkText
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Pending Changes"))).click();
:css选择器
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[id^=id_][alt^='Title']"))).click();
:xpath
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[starts-with(@id,'id_') and starts-with(@alt,'Title')]"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[starts-with(@id,'id_') and starts-with(@alt,'Title')]"))).click();