我如何克服Selenium中的Element id异常? [英] How can I overcome Element id exception in Selenium?

查看:160
本文介绍了我如何克服Selenium中的Element id异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

T为UiBinder本身的GWT小部件设置'id'。





在* .gwt.xml中添加



然后我在Selenium测试用例中试试这个

  WebElement element = driver.findElement(By.id(gwt-debug- loginButton)); 

有时它可以正常工作。但有时它会抛出以下异常:

lockquote
无法找到元素
{method:id,选择器:gwt-debug-loginButton}命令持续时间或
超时:62毫秒

我需要更新?
任何人都可以帮助我吗?

解决方案

使用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));
返回true;
} catch(异常e){
返回false;
}
}
});
} catch(TimeoutException t){
//在这段时间内未找到元素
}


T set 'id' for GWT widgets in UiBinder itself.

For eg.

Also added in *.gwt.xml

Then I try this in Selenium test case

WebElement element = driver.findElement(By.id("gwt-debug-loginButton"));

Sometimes it works correctly. But some times it throws the following exception,

Unable to locate element: {"method":"id","selector":"gwt-debug-loginButton"} Command duration or timeout: 62 milliseconds

What i need to update? Can anyone help me?

解决方案

Use WebDriverWait, to search for element after a certain period of time. Something like this.

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
    }

这篇关于我如何克服Selenium中的Element id异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆