我想在 selenium 中的一個元素上單擊 5 次我如何使用 for 回圈或 while 回圈在 python 中執行此操作我已經嘗試在 python 中使用 for 回圈下面是代碼
nextButton = driver.find_element_by_id("com.sustlabs.ohmassistant:id/btn_next")
for nextButton in range(5):
nextButton.click()
uj5u.com熱心網友回復:
要使用Selenium在元素上click() 5 次,您可以使用 _回圈并為element_to_be_clickable()引入WebDriverWait,如下所示:for()_
for i in range(5):
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "com.sustlabs.ohmassistant:id/btn_next"))).click()
注意:您必須添加以下匯入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/402079.html
上一篇:改變for回圈的迭代方向
