单击超链接中的Selenium Webdriver问题

时间:2018-11-21 06:03:59

标签: selenium selenium-webdriver xpath css-selectors webdriverwait

尝试使用Selenium Web驱动程序单击超链接时遇到问题。我尝试使用Selector以及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>

2 个答案:

答案 0 :(得分:1)

该元素是JavaScript启用的元素,因此您需要诱使 WebDriverWait 使元素可点击,并且可以使用以下解决方案之一: / p>

  • Java解决方案:

    • new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Pending Changes"))).click();

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

      docker pull

答案 1 :(得分:0)

Java:

driver.findElement(By.linkText("Pending Changes")).click();

driver.findElement(By.id("d_34")).click();