2017-09-14 65 views
0

硒/ JAVA PhantomJs:Selenium/java PhantomJs driver.get(loginURL)首次运行时获取登录网址。在第二次运行它driver.get(loginURL)首页

第一次运行,driver.get(loginURL),获取登录URL。

第二次运行时,driver.get(loginURL)转到主页,而不是登录页面。当然,它没有找到登录页面的元素。

(脚本执行可能失败并注销我不是在年底完成)

任何帮助吗?任何想法为什么发生这种情况?

感谢

代码部分和异常:

控制台打印输出的 ​​

Reults:

第1轮:网址:https://xxxxxx/yy/login(正确,还发现旁边WebElements),未能在接下来的步骤

第2次运行:网址:https://xxxxxx/yy/home(不正确应该是登录页面https://xxxxxx/yy/login

抛出异常:org.openqa.selenium.NoSuchElementException: { “的errorMessage”: “无法找到ID元件 'TXT-用户名'”

+0

Qunestion不清楚。你能详细说明一下吗? – imBollaveni

回答

0

对于适当的清理(故障后注销在你的情况下),你可以实施一个拆卸方法,在你的测试类的每次测试后执行,例如像这样(使用Junit4):

@org.junit.After 
public void tearDown() { 
    //your code for performing logout 
    //.... 

    //Close the current window, quitting the browser 
    //if it's the last window currently open. 
    if (driver != null) { 
     driver.close(); 
    } 
}