Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a page is switched to another page using Selenium in Python

The following code opens a page and then logins in:

self.driver.get(target_url)
login = self.driver.find_element_by_name("login")
login.send_keys("user1")
password = self.driver.find_element_by_name("password")
password.send_keys("password123")
login.submit()

How do I check if the page is switched to another page after submitting the form?

like image 833
JD Francis Avatar asked Jun 17 '16 22:06

JD Francis


People also ask

How do I switch pages in Selenium Python?

For Selenium to switch to a particular window, one needs to use the switch_to_window method. Pass the window handle ID of the target tab where the user wants to switch as an argument to that method.

What is ElementNotInteractableException Selenium?

Class ElementNotInteractableExceptionThrown to indicate that although a WebElement is present on the DOM, it is not in a state that can be interacted with. This includes an element that is not displayed or whose center point can not be scrolled into the viewport.


2 Answers

Use an explicit wait with an expected condition to tell when one of your login elements has gone stale:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

self.driver.get(targeturl)
login = self.driver.find_element_by_name("login")
login.send_keys("user1")
password = self.driver.find_element_by_name("password")
password.send_keys("password123")
login.submit()

WebDriverWait(self.driver, timeout).until(EC.staleness_of(login))
like image 179
Levi Noecker Avatar answered Sep 18 '22 11:09

Levi Noecker


    while(self.driver.getCurrentUrl() != nextPageUrl)
like image 26
AlexCharizamhard Avatar answered Sep 19 '22 11:09

AlexCharizamhard