【问题标题】:Selenium webdriver error Unable to find element on (bamboo)Selenium webdriver错误无法在(竹子)上找到元素
【发布时间】:2018-11-01 13:20:00
【问题描述】:

我是 selenium 的新手,正在使用 Chrome 网络驱动程序。

我要点击的元素是

<a href="/myclassroom/studentsclass" class="current">Students</a>

我写了一点代码来点击链接

driver.findElement(By.(linkText("Students")).click();

我尝试过的其他方法

driver.findElement(By.xpath(a[@href="/myclassroom/studentsclass"])).click();

上面(两个)代码在 Windows 上本地运行良好,但是当我将它推到竹子执行它的 bitbucket 上时。它返回未找到的错误元素。

错误的可能原因是什么? 谢谢。我们将不胜感激。

【问题讨论】:

  • 在你的 CI 中运行它的浏览器是什么?它可能无法正确呈现元素,或者可能无法正确解释元素。如果问题出在元素丢失或硒中,您可以尝试使用 css 选择器
  • 我已经尝试过使用 css selsctor 但同样的问题。

标签: java selenium google-chrome selenium-webdriver bamboo


【解决方案1】:

这可能是服务器加载时间较长的问题,添加一些等待

WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Students"))).click();;

【讨论】:

  • 好的,我正在测试。我会在测试后立即回复。谢谢
  • 你能告诉我implicitlyWait和上面你写的方法有什么区别吗。
  • @RamzanMahmood implicitlyWait 将等待元素存在于 DOM 中。显式等待(WebDriverWait)将等待 ExpectedCondition(在这种情况下为elementToBeClickable)。
【解决方案2】:

你可以列个清单:

List<WebElement> elements= driver.findElement(By.id("current").findElements(By.tagName("a"));
for (int j = 0; j <= elements.size(); j++) {
   if(elements.get(i).getText().equals("Students")){
      elements.get(i).click();
      break;
   }
}

【讨论】:

    猜你喜欢
    • 2014-07-13
    • 2014-05-29
    • 2016-12-12
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多