我正在尝试以编程方式单击运行在ubuntu服务器上的脚本的按钮,以访问网站内容。我正试图用菜谱访问这个网站。
这是我的密码:
driver = webdriver.Firefox(executable_path="/home/ubuntu/.linuxbrew/Cellar/geckodriver/0.26.0/bin/geckodriver",options=options)
data = []
# In[34]:
# click GDPR full-width banner
start_time = datetime.now()
driver.get("http://some_web_site.here/")
time.sleep(10)
# gdpr_button = driver.find_element_by_link_text("Continue")
#gdpr_button = driver.find_element_by_xpath('//button[text()="Continue"]')
driver.find_element_by_xpath("//input[@style='order:2' and @onclick='sendAndRedirect()']").click()
# //input[@onclick='sendAndRedirect()']
# <button style="order:2" onclick="sendAndRedirect();">Continue</button>但是,我无法到达元素并获得
selenium.common.exceptions.TimeoutException: Message: connection refused如何访问GDPR表单中的“继续”按钮?感谢你的帮助
发布于 2020-03-12 20:48:42
所需的元素是一个动态元素,因此要在该元素上定位/click(),需要为element_to_be_clickable()诱导WebDriverWait,您可以使用以下任何一个定位器策略
CSS_SELECTOR:
20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,(WebDriverWait)(驱动程序,按钮点击^=‘sendAndRedirect’)).click()XPATH和innerText事件:
(驱动程序,20).until(EC.element_to_be_clickable((By.XPATH,“//WebDriverWait=‘WebDriverWait’).click()XPATH和onclick事件:
( 20).until(EC.element_to_be_clickable((By.XPATH,“//WebDriverWait-with(@onclick,‘sendAndRedirect’)”)).click()https://stackoverflow.com/questions/60661525
复制相似问题