在 UiBinder 本身中为 GWT 小部件设置“id”。
例如。
还在 *.gwt.xml 中添加了
然后我在 Selenium 测试用例中试试这个
WebElement element = driver.findElement(By.id("gwt-debug-loginButton"));
有时它可以正常工作。但有时它会抛出以下异常,
Unable to locate element: {"method":"id","selector":"gwt-debug-loginButton"} Command duration or timeout: 62 milliseconds
我需要更新什么? 谁能帮帮我?
最佳答案
使用WebDriverWait,在一定时间后搜索元素。像这样。
try {
(new WebDriverWait(driver, seconds, delay)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
try {
WebElement el = d.findElement(By.id("gwt-debug-loginButton"));
return true;
} catch (Exception e) {
return false;
}
}
});
} catch (TimeoutException t) {
//Element not found during the period of time
}
关于gwt - 如何克服 Selenium 中的 Element id 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11862866/