繁体   English   中英

Selenium Webdriver等待,元素不可点击异常

[英]Selenium webdriver wait, Element not clickable exception

我正在使用硒的webdriver chrome。 我正在测试一个包含许多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 wait的正确方法是什么。 TY

这一翻译使用presenceOfElementLocated,尽量一次visibilityOfElementLocated。

  • visibleOfElementLocated:它检查元素是否可见并存在。
  • presentOfElementLocated:它只是检查DOM中是否存在元素。

有关更多信息,请使用下面的链接- “ ExpectedConditions.visibilityOfElementLocated”和“ ExpectedConditions.presenceOfElementLocated”之间的确切区别是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM