gwt - 如何克服 Selenium 中的 Element id 异常?

标签 gwt selenium selenium-webdriver gwt2 selenium-server

在 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/

相关文章:

java - 如何在不使用反射的情况下将 Java 对象转换为键值对

GWT i18n 和图像

javascript - 如何在具有相同名称但文件不同的javascript链接的页面中获取selenium的xpath?

javascript - 在 Chrome 等中进行 Canvas 操作(fillRect() 等)时内存消耗的问题

java - GWT 模拟框架的综合优点/缺点

java - findElement 在运行时生成 HTML

jquery - 如何使用 Splinter 单击存在但不可见的复选框? ( Selenium / python )

java - Selenium(JAVA) 网格仅在 Windows 中同时启动 10 个浏览器

java - 如何在 Selenium webdriver 中等待输入字段刷新

java - 在 Selenium 3 中使用 xpath 定位元素时出现错误