【问题标题】:Anchor tag is not clickable [duplicate]锚标记不可点击[重复]
【发布时间】:2020-05-21 05:15:21
【问题描述】:
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//a[contains(text(),'Download')])")));   
WebElement download = driver.findElement(By.xpath("(//a[contains(text(),'Download')])"));
download.click();

我正在尝试通过 selenium 单击 chrome 中的下载链接。它在页面中有许多其他链接,并且这些链接都在工作,但仅此下载链接就会导致 timeout exception。

并且页面中的锚标记如下

<a href="https://www.somexyz.com/key/url?url=http%3A//www.somexyz.net/webform_protected_file/lwhW0167ec9HZBEefQrIoSg6JpnW0zvlQyxL-iaR8Ms/download" target="_other" rel="nofollow">Download file</a>

任何建议将不胜感激。

【问题讨论】:

  • 是否还有更多带有Download 文本的元素?是在iframe里面吗?
  • anchor标签里面的url能给出答案吗?
  • 请检查链接是否在 iframe 中?如果是,则在单击之前切换到框架。
  • 谢谢大家。是的,链接在 iframe 中,所以需要切换到该框架,然后必须点击链接。

标签: java selenium selenium-webdriver selenium-chromedriver


【解决方案1】:
driver.switchTo().frame("msg_body");
                WebDriverWait wait = new WebDriverWait(driver,30);
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//a[contains(text(),'Download')])")));   
                WebElement download = driver.findElement(By.xpath("(//a[contains(text(),'Download')])")); 
                download.click();

上面的代码对我有用,首先将驱动程序切换到预期的 iframe,然后选择有效的链接。

【讨论】:

    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多