Issue
I am very new so I would need some help. Can you help me create a loop for the following actions. Click on all buttons and refresh the page and then do it 100 more times for example.enter image description here
Solution
Based on the minimal sample you provided, you can refactor this pretty easily. Here's how I would fix that:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# wait on buttons
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located(
(By.XPATH, "//*[@class='btn default check check green markAsChecked']")))
buttons = driver.find_elements_by_xpath("//*[@class='btn default check check green markAsChecked']")
# click buttons in a loop
for button in buttons:
button.click()
I added a WebDriverWait between buttons, as it's better practice to wait on elements before clicking them.
Answered By - CEH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.