[英]Issue with WebDriver test case
I have written a test case using WebDriver, I closed the browser in one method and again I am opening the browser not able to invoke 我已经使用WebDriver编写了一个测试案例,用一种方法关闭了浏览器,然后再次打开无法调用的浏览器
driver.close();
i closed the browser through above command for again opening a browser i driver.get(url)
but i am getting error 'Error communicating with the remote browser It may have died' 我通过上述命令关闭了浏览器,再次打开了我的浏览器
driver.get(url)
但出现错误“与远程浏览器通信出错,可能已死亡”
Well you killed the browser with your driver.close();
好吧,您用
driver.close();
杀死了浏览器driver.close();
In order to use the driver you must create a new one using something like driver = new FirefoxDriver(capabilities);
为了使用该驱动程序,您必须使用
driver = new FirefoxDriver(capabilities);
类的东西来创建一个新driver = new FirefoxDriver(capabilities);
If you really want to close the browser before navigating to the new URL, then do: 如果您确实要在导航到新URL之前关闭浏览器,请执行以下操作:
driver.quit();
driver = new FirefoxDriver();
driver.get(url);
However, why would you want to close the browser before navigating to the new URL in the first place? 但是,为什么要先导航到新URL之前关闭浏览器?
I can think of either one of two reasons: 我可以想到以下两个原因之一:
You want to go to the next URL with your browser's history cleaned. 您想转到下一个URL,并清除浏览器的历史记录。
If this is indeed the case, then deleteAllCookies
will do the job. 如果确实如此,那么
deleteAllCookies
将完成此工作。
You cannot go to the next URL because some popup alert is preventing you doing it. 您无法转到下一个URL,因为某些弹出警报阻止您执行此操作。
If this is indeed the case, then neither close
not quit
will do the job. 如果事实确实如此,那么既不
close
不quit
将做的工作。
Moving to answer from comment. 从评论开始回答。
I think I got your issue. 我想我有你的问题。 Though you have called the close() and it only should close the current window, you should use this if you want to shift between multiple windows.
尽管您已经调用close(),并且它仅应关闭当前窗口,但是如果要在多个窗口之间切换,则应使用此方法。
For your case just don't close the driver it will use the same window to open the url. 对于您的情况,只是不要关闭驱动程序,它将使用相同的窗口打开URL。
You have to use following way if you want to close the current browser and open
a new one:
webDriver.Close();
//Goto the Target website
WebDriver.Navigate().GoToUrl("url");
And you can use following way if you want to close the browser and kill the
web driver:
webDriver.Close();
webDriver.Quit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.