Selenium WebDriver findelement stuck java?

泄露秘密 提交于 2019-12-13 00:47:57

问题


I am writing a very simple test case using selenium webdriver. Lets say I have

@Test
public void github_search() {
    this.webDriver.get("http://www.github.com");

    WebElement findBox = this.webDriver.findElement(By.id("qa"));

......
}

in this test, there is no element on the page with id of "qa", in this case I am excepting the findElement method to throw an exception. But it doesn't. Selenium actually appears to be stuck. Only thing I could do is manually close the browser. I was wondering how to handle such situation where if the element doesn't exist then it waits for some time and, finally it should just throw an exception.


回答1:


Just download latest 2.27 release:

https://code.google.com/p/selenium/downloads/list




回答2:


Use try catch Block and use implicit wait.



来源:https://stackoverflow.com/questions/13711799/selenium-webdriver-findelement-stuck-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!