【问题标题】:Selenium webdriver wait, Element not clickable exceptionSelenium webdriver 等待,元素不可点击异常
【发布时间】:2018-02-19 06:55:34
【问题描述】:

我正在为 chrome 使用 selenium webdriver。 我正在测试一个包含大量 ajax 内容的 Web 应用程序,因此在登录到应用程序后,需要几秒钟才能在主页中加载 ajax 内容。

我在登录后使用了显式等待来等待找到元素。但它大多失败。我给了 25 秒的等待时间,但等待 4 秒后它失败了。 错误是,...

Unknown error: Element <a href="/ls/create_new" class="ajax addDashButton hasLink">...</a> is not clickable at point (144, 223). 

其他元素会收到点击: (会话信息:chrome=60.0.3112.78) (

我的代码是..

public class login {
    WebDriver driver;

  @Test
  public void f() {

      System.setProperty("webdriver.chrome.driver", "filepath/chromedriver");
      driver = new ChromeDriver();
  driver.get("URL");
  driver.manage().window().maximize();

      driver.findElement(By.name("username")).sendKeys("username");
      driver.findElement(By.name("password")).sendKeys("password");
      driver.findElement(By.className("login")).click();

      WebDriverWait wait = new WebDriverWait(driver, 25);

      wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Create New App")));
      driver.findElement(By.linkText("Create New App")).click();
  }
}

这只是我的代码的一部分..使用 webdriver 等待的正确方法是什么。 TY

【问题讨论】:

  • 我认为它能够找到元素,只是它找到的元素在您尝试时不可点击。这就是日志读取的内容。
  • 您能分享您的网站网址吗?
  • 网址是 demo.vizru.com

标签: java selenium-webdriver selenium-chromedriver


【解决方案1】:

如果不使用 presenceOfElementLocated,请尝试一次 visibilityOfElementLocated

  • visibilityOfElementLocated:它检查元素是否应该可见和存在。
  • presenceOfElementLocated:它只是检查元素是否存在于 DOM 中。

欲了解更多信息,请查看以下链接- What is the exact difference between "ExpectedConditions.visibilityOfElementLocated" and "ExpectedConditions.presenceOfElementLocated"

【讨论】:

  • 是的..现在它似乎工作了谢谢。我还有一个疑问..我可以声明所有测试用例中常见的 webdriver 等待时间吗?我如何在父类中使用(WebDriverWait wait = new WebDriverWait(driver, 25);)这个方法,所以所有子类都可以访问。我是 Java 新手
  • 不错的答案@imBollaveni
  • @JithinEzio 在父类中声明等待和驱动程序为静态变量。这样您就可以在所有孩子的班级中使用它们。例如:静态 WebDriver 驱动程序;静态 WebDriverWait 等待;
猜你喜欢
  • 2012-03-26
  • 1970-01-01
  • 2020-02-23
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
  • 1970-01-01
  • 2018-03-14
  • 2015-05-03
相关资源
最近更新 更多