Selenium/python无法单击elemen

2024-05-23 19:44:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用python和selenium去一个网站收集一些数据,但我甚至无法通过最初的弹出窗口,要求我单击Accept按钮同意使用条款!网站是here

我可以看到'Accept'链接/div有一个id,我尝试过使用find_element_by_xpath并选择id,然后尝试单击,但这不起作用。在

我也尝试过使用ActionChains导航到按钮并单击,但这也不起作用。它返回的错误是元素在点不可单击。。。

似乎有一些jquery/javascript在后台运行,这很难处理!在

任何帮助都将不胜感激。在


Tags: 数据dividbyhere网站链接selenium
1条回答
网友
1楼 · 发布于 2024-05-23 19:44:01

诀窍是等待“Accept”(接受)按钮变为可点击,移动到该按钮并单击:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Firefox()
driver.get("https://www.etfsecurities.com/institutional/uk/en-gb/products.aspx")

wait = WebDriverWait(driver, 10)
accept = wait.until(EC.element_to_be_clickable((By.ID, "btnPopupAccept")))

actions = ActionChains(driver)
actions.move_to_element(accept).click().perform()

相关问题 更多 >