Selenium 网络驱动程序 : Unable to click a link (Not inside iframe- able to print gettext value from the webelement)

标签 selenium selenium-webdriver

请不要评论我为什么发布类似的问题。我已经尝试了很多事情,但没有任何效果。下面是 HTML

    <div id="businessSettingsColumn1">
       <div class="sectionLink"> 

       <a href="serviceprovider/30015514/settings/details">Business details</a>
       </div>
      <div class="sectionLink">
        <a href="serviceprovider/30015514/settings/hours">Operating hours</a>
      </div>
     <div class="sectionLink">
     <a href="settingsserviceproviderleave.action?purpose=closed">Closed dates</a>
     </div>
     <div class="sectionLink">
      <a href="serviceprovider/30015514/settings/booking/notifications">Appointment            notifications</a>
  </div>

我需要点击第二个链接 我已经尝试过了

1) webdriver.findElement(By.partialLinkText("营业时间")).click();

2)webDriver.get(mylement.findElement(By.tagName("a")).getAttribute("href"));

3)

List<WebElement> businessLinks= busCol.findElements(By.className("sectionLink"));

    for(WebElement bLink :businessLinks) {
    if(bLink.getText().contains("Operating hours")) {

    bLink.findElement(By.tagName("a")).click();
    }
            }

4) 使用操作构建器移动鼠标,然后单击

此外,当我连续执行此操作 3 次时,我的元素被点击

webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();

我使用的是 Firefox 版本 25.0 和 Selenium 版本 2.35.0。有趣的是,当我执行 sysout 时,值会被打印出来,当我尝试使用 webdriver 获取 url 时,我得到“在缓存中找不到元素 - 也许页面自从查找以来已经发生了变化”.. 它几乎仅包含链接的静态页面,所以我不明白为什么我无法单击它。任何帮助将不胜感激。

最佳答案

您可以尝试在单击元素之前调用 focus() 吗?

关于 Selenium 网络驱动程序 : Unable to click a link (Not inside iframe- able to print gettext value from the webelement),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19993229/

相关文章:

java - Selenium Java - 使用 Getters 和 Setters 的 TestNG 数据提供程序

Python Selenium 抓取不正确的括号集(Python、Selenium、MySQL)

java - 动态表数据检索 - selenium webdriver

java - 重新加载页面,但保留 DOM 保存

angularjs - Protractor - 当 DOM 元素更改时,页面对象不会更新

python - 使用 Selenium/Python 验证 div 中是否存在文本时出现问题

selenium - 使用 Selenium ChromeDriver ChromeOptions 清除缓存

selenium - 为什么我们不写 RemoteWebdriver driver = new ChromeDriver();

java - 如何从命令提示符运行已完成的 Selenium-RC 项目?

selenium - 启动 : Windows opens many instances of Edge, 每个都带有 "ERROR:file_io_win.cc(180)] CreateFile settings.dat: Access is denied. (0x5)"