我正在使用selenium webdriver for 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等待的正确方法是什么。 TY
答案 0 :(得分:2)
使用 presenceOfElementLocated 的Intead,尝试 visibilityOfElementLocated 。
有关更多信息,请查看以下链接 - What is the exact difference between "ExpectedConditions.visibilityOfElementLocated" and "ExpectedConditions.presenceOfElementLocated"