For loop selenium click

1k views Asked by At

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()
1

There are 1 answers

3
undetected Selenium On BEST ANSWER

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