selenium with python:如何单击网页上某种类型的所有按钮

发布于 2025-01-31 02:00:57 字数 900 浏览 1 评论 0原文

我正在尝试单击网页上某种类型的所有按钮,并从生成的弹出框中删除信息。到目前为止,我编写的代码在前4个按钮上都可以使用,下一步我会收到以下错误消息:

element notintactableException:消息:元素不相互作用

是我到目前为止写的代码:

driver = webdriver.Chrome()

url = 'https://www.handyverkauf.net/macbook-verkaufen/macbook-pro'
    
time.sleep(3)
driver.get(url)
time.sleep(3)


buttons = driver.find_elements_by_xpath("//a[@class='uk-button uk-button-small uk-button-primary']//span[@class='uk-hidden-small'][contains(text(),'Zum Vergleich')]")

buttons[4].click()

网页是: https://www.handyverkauf.net/macbook-verkaufen/macbook-pro

我已经附加了一个 ScreenShot 在这里显示我想单击的按钮。第一个4“ zum vergleich”工作正常(对于MacBook Pro 2021),但第五(MacBook Pro 2020)停止工作。

I am trying to click through all buttons of a certain type on a webpage and scrape the info from the resulting pop up boxes. The code I wrote so far works on the first 4 buttons and on the next I get the following error message:

ElementNotInteractableException: Message: element not interactable

Here is the code I wrote so far:

driver = webdriver.Chrome()

url = 'https://www.handyverkauf.net/macbook-verkaufen/macbook-pro'
    
time.sleep(3)
driver.get(url)
time.sleep(3)


buttons = driver.find_elements_by_xpath("//a[@class='uk-button uk-button-small uk-button-primary']//span[@class='uk-hidden-small'][contains(text(),'Zum Vergleich')]")

buttons[4].click()

The webpage is this: https://www.handyverkauf.net/macbook-verkaufen/macbook-pro

I have attached a
screenshot here which shows the buttons I would like to click. The first 4 'Zum Vergleich' work fine (for the MacBook Pro 2021) but then the fifth (for the Macbook pro 2020) stops working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文