If the browser window is not in focus, all webdriver identifications on the current page fail.
How can the browser be brought into focus, using webdriver?
If the browser window is not in focus, all webdriver identifications on the current page fail.
How can the browser be brought into focus, using webdriver?
executeScript("window.focus();")
didn't work for me in the latest Chrome (v47 at the time of this post)
However I found a hack in another question which does work in this version of Chrome.
Here are the generic steps, since the question doesn't specify the Selenium API language:
Implementation in webdriverjs
, which I'm using
const chrome = setupChromeWebdriver(); // get your webdriver here
chrome.executeScript('alert("Focus window")'))
.then(() => chrome.switchTo().alert().accept());
((JavascriptExecutor) webDriver).executeScript("window.focus();");
should do the trick!
This works for me. After the code that opens the browser, issue this snippet:
String window = driver.getWindowHandle();
((JavascriptExecutor) driver).executeScript("alert('Test')");
driver.switchTo().alert().accept();
driver.switchTo().window(window);
Selenium 3.0 takes this:
((IJavaScriptExecutor)po.WebDriver).ExecuteScript("window.focus();");
attention
message. –
Socialite Setting the focus at the "driver options" should work:
InternetExplorerOptions options = new InternetExplorerOptions();
options.setCapability("requireWindowFocus", true);
This works for me (in python):
driver.minimize_window()
driver.maximize_window()
© 2022 - 2024 — McMap. All rights reserved.
driver.switchTo().defaultContent()
(and/orswitchTo().activeElement()
) helps - mostly on IE. What's your use case? – Renounce