1
我颳了一個動態頁面,要求用戶多次單擊「加載更多結果」按鈕才能獲取所有數據。有更好的方法來處理顯示時點擊元素的任務嗎?Python selenium點擊元素,同時顯示
def clickon(xpath):
try:
element = driver.find_element_by_xpath(xpath)
except:
print "RETRYING CLICKON() for %s" % (xpath)
time.sleep(1)
clickon(xpath)
else:
element.click()
time.sleep(3)
def click_element_while_displayed(xpath):
element = driver.find_element_by_xpath(xpath)
try:
while element.is_displayed():
clickon(xpath)
except:
pass