I want to click 5 times on an element in selenium how can i do this using for loop or while loop in python i have tried using for loop in python below is the code
nextButton = driver.find_element_by_id("com.sustlabs.ohmassistant:id/btn_next")
for nextButton in range(5):
nextButton.click()
CodePudding user response:
To click() 5 times on an element using Selenium you can use a _for()_
loop and inducing WebDriverWait for the element_to_be_clickable()as follows:
for i in range(5):
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "com.sustlabs.ohmassistant:id/btn_next"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC