简体   繁体   中英

How to call all the functions in Selenium when a page is refreshed?

I was using selenium automation in Python on a login page. I have send my keys in email and password textbox using:

driver.find_element_by_id("loginId").sendKeys("mailid")

and

driver.find_element_by_id("pass").send_Keys("password")

When I click on Log In button then the page is refreshed and just in case if my id and password combination is wrong. But how can I automate so that when my page is refreshed, at least the id and pass field is filled again? Or that means if my password is wrong and I've redirected to the same page again, how can I fill those boxes again. How to check if the page is refreshed automatically or not?

def login():
     driver.find_element_by_id("usernameId").send_keys('username')
     driver.find_element_by_id("pwd").send_keys('password')
     driver.find_element_by_id("logIn").click()
     # tell me what to write here in case I got an error saying invalid id and pass combination.

login()

Because many times I need a lot of things that are better done manually, logins, capcha, robot checks, authentications, extensions certain cookies, etc

I use folders as profiles, I run:

chrome_options = Options()
chrome_options.add_argument("user-data-dir=custom_folder_1") 
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("www.google.com")

Then I manually install the Extensions and do the logins I need now every-time I start the Webdriver with that folder everything is there

chrome_options = Options()
chrome_options.add_argument("user-data-dir=custom_folder_1") 
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("www.google.com") #Now you can see the logins done are present

The advantage is you can use multiple folders with different setting and Extensions without the need to install and uninstall Extensions, change settings, change logins etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM