How to fully close Opera browser via RemoteWebDriver

夙愿已清 提交于 2020-01-07 04:04:26

问题


I'm attempting to add Opera to a node on our Selenium Grid but running into a problem closing the Opera browser. In Opera, closing the last tab in a browser does not close the browser. It instead launches something called Speed Dial. This is apparently the default behavior in Opera. I've tried to disable Speed Dial but it doesn't appear to prevent this behavior.

Due to the tests running via RemoteWebDriver, I can't just call a script on the Opera node to close the window.

I've tried the traditional method, which closes the tab but then Opera launches either an empty or speed dial tab:

driver.close();
driver.quit();

I've tried performing an action and sending keys into the html body:

Actions action = new Actions(driver);
action.sendKeys(driver.findElement(By.xpath("//body")),Keys.CONTROL, Keys.SHIFT, "W");
action.build().perform();
driver.quit();

I've also tried building an action and sending keys into the ether:

Actions action = new Actions(driver);
action.sendKeys(Keys.CONTROL, Keys.SHIFT, "W");
action.build().perform();
driver.quit();

Has anyone found a suitable workaround for this 'feature'?


回答1:


I've found this issue.

So thanks to the Kryshtopenko the solution is:

  • For windows:

    Runtime.getRuntime().exec("taskkill /f /im opera.exe");

  • For macOS:

    Runtime.getRuntime().exec("pgrep 'Opera' | xargs kill");




回答2:


I found a workaround for this. My code is in C#

Utility.Instance.KillProcess("opera");
System.Windows.Forms.SendKeys.SendWait("{ESC}");
Utility.Instance.KillProcess("operadriverserver");

Hope it will help you.



来源:https://stackoverflow.com/questions/45717985/how-to-fully-close-opera-browser-via-remotewebdriver

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