单击超链接时出现Selenium webdriver问题

单击超链接时出现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&

尝试使用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>

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();
      

您可以编辑带有其他详细信息的问题帖子-无需将其放在评论中。另外,格式化代码。这里有一些要点。嗨,谢谢。但它对我不起作用。因为有4个表,其中一个表中有一行有此挂起的更改超链接。你能帮助我吗
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[starts-with(@id,'id_') and starts-with(@alt,'Title')]"))).click();