executeScript("window.focus();") did not work for me in the latest version of Chrome (v47 at the time of publication)
However, I found a hack in another question that works in this version of Chrome.
Here are the general steps since the Selenium API language is not specified in the question:
- Show warning by running script in browser
- Receive alert
The implementation in webdriverjs that I use
const chrome = setupChromeWebdriver(); // get your webdriver here chrome.executeScript('alert("Focus window")')) .then(() => chrome.switchTo().alert().accept());
davnicwil
source share