I am exporting my selenium test to python and running the test using the shell. I get to a certain point where I click on a link and the web-driver then opens a completely new Firefox window and then I get an error saying that the driver can't find the input option on the page. I think the problem is that when it opens the new window the driver is not running on the new window, which is why it can't find the input option. How do I get the script to stay on the same window or switch it's focus to the new window?
Thanks!
Open a New Tabget('https://selenium.dev'); // A new tab is opened and switches to it await driver. switchTo(). newWindow('tab'); // Loads Sauce Labs open source website in the newly opened window await driver. get('https://opensource.saucelabs.com/');
We can switch back from a frame to default in Selenium webdriver using the switchTo(). defaultContent() method. Initially, the webdriver control remains on the main web page. In order to access elements within the frame, we have to shift the control from the main page to the frame with the help of the switchTo().
We can stop a page loading with Selenium webdriver in Chrome browser by using the JavaScript Executor. Selenium can execute JavaScript commands with the help of the executeScript command. To stop a page loading, the command window. stop() is passed as a parameter to the executeScript method.
In your case you have to use driver. close() which will close current window and keeps driver active. Just to add - if there is only browser window open and you use driver. close() , it will quit the webdriver session.
I don't know how to do it in python, but there should be a function to switch to a new window.
In Java, I do this:
Set<String> availableWindows = driver.getWindowHandles();
for (String windowHandle : availableWindows) {
driver.switchTo().window(windowHandle);
if (getTitle().contains(TITLE_TO_MATCH)){
driver.manage().window().maximize();
return;
}
}
(The function want is driver.switchTo().window(NameOrHandle)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With