![](/img/trans.png)
[英]Segmented scroll down page to check for existence of element - Python selenium, driver.execute_script
[英]Python, Selenium: How to check existence of an element?
我试图一次浏览一个网站,单击next
元素,该元素在HTML代码中为class="pg-next"
。 最终,尽管如此,我要结束了,再也没有next
元素了,在这一点上,我想停止循环。 我有这样的事情:
pg_next_exists = True
while pg_next_exists:
#
# carry out necessary actions
#
if ...: # if the pg-next element can be found
pass
else:
pg_next_exists = False # at which point the while loop stops
如何检查该元素是否仍然存在?
你为什么不使用wait
尝试这样的事情
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Firefox()
browser.get('http://example.com/')
try:
wait = WebDriverWait(browser, 10)
search = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'next')))
search.click()
except:
# Process element not found here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.