Home > Software design >  How to loop the execution of a script on selenium?
How to loop the execution of a script on selenium?

Time:10-16

Need help from the community. I'm new to Python and don't understand how to loop the execution of a selenium script.

from selenium import webdriver
import time

driver = webdriver.Firefox()

def change_password():
    driver.get("http://nsagov.ru/Users/Login.aspx")
    driver.find_element_by_xpath("/html/body/form/div[4]/div[1]/table/tbody/tr/td/div/table/tbody/tr[4]/td/div/a/span").click()
    driver.find_element_by_id("ContentPlaceHolder1_GetNewPasswordPopup_EmailTB_I").send_keys("[email protected]")
    driver.find_element_by_xpath("//div[@id='ContentPlaceHolder1_GetNewPasswordPopup_TPCFm1_GetPasswordButton_CD']/span").click()
    
change_password()

time.sleep(5)
driver.quit()

CodePudding user response:

you can use this process

for i in range(10):
    driver.get("http://nsagov.ru/Users/Login.aspx")
    driver.find_element_by_xpath("/html/body/form/div[4]/div[1]/table/tbody/tr/td/div/table/tbody/tr[4]/td/div/a/span").click()
    driver.find_element_by_id("ContentPlaceHolder1_GetNewPasswordPopup_EmailTB_I").send_keys("[email protected]")
    driver.find_element_by_xpath("//div[@id='ContentPlaceHolder1_GetNewPasswordPopup_TPCFm1_GetPasswordButton_CD']/span").click()
    driver.execute_script("window.open('');")
    time.sleep(2)
    driver.switch_to.window(driver.window_handles[-1])

which create a new tab and follow the code again

  • Related