简体   繁体   English

刷新页面后如何调用Selenium中的所有函数?

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

I was using selenium automation in Python on a login page. 我在登录页面上的Python中使用了硒自动化。 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. 当我单击“ 登录”按钮时,页面将刷新,以防万一我的ID和密码组合错误。 But how can I automate so that when my page is refreshed, at least the id and pass field is filled again? 但是,如何使我自动化,以便在刷新页面时至少再次填充id和pass字段? 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 因为很多时候我需要做很多更好的手动操作,例如登录,验证码,机器人检查,身份验证,某些Cookie的扩展名等

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 然后,我每次手动安装扩展程序并执行我现在需要的登录时,使用该文件夹启动Webdriver

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 优点是您可以使用具有不同设置和扩展名的多个文件夹,而无需安装和卸载扩展名,更改设置,更改登录名等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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