org.openqa.selenium.NoSuchElementException: no such element

前端 未结 7 1948
深忆病人
深忆病人 2020-12-09 13:35

Running Selenium WebDriver 2.37.1

I\'m receiving an intermittent problem when running a test and receive the following error:

org.openqa.selenium.No         


        
7条回答
  •  囚心锁ツ
    2020-12-09 14:15

    did you open a new window? If yes, you need make driver to switch to the new window, following code is tested by me:

    String currentWindow = driver.getWindowHandle();// get handle of current window
    Set handles = driver.getWindowHandles();// get handle of all windows
    Iterator it = handles.iterator();
    while (it.hasNext()) {
    if (currentWindow == it.next()) {
    continue;
    }
    driver = driver.switchTo().window(it.next());// switch to new window
    
    //business action
    //xxxxxxx
    }
    driver.switchTo().window(currentWindow);//switch back to original window
    

提交回复
热议问题