python - 无法使用selenium单击div按钮

标签 python selenium web-scraping

我想单击一个实际上是 div 标签的按钮。我无法点击它。

from selenium import webdriver

url = "https://www.qoo10.sg/item/LAPTOP-SCREEN-PROTECTOR-SCREEN-GUARD-FOR-13-14-15-INCHES-2ND/410235318"

driver = webdriver.Firefox()
driver.get(url)

elem = driver.find_element_by_class_name('selectArea').click()

当我运行这个程序时,出现这个错误

selenium.common.exceptions.ElementNotInteractableException: Message: Element <div id="ship_to_outer" class="selectArea"> could not be scrolled into view.

最佳答案

有 4 个按钮具有相同的类名“ship_to_outer” - 第一个按钮是隐藏的,因此您无法单击它。请尝试下面的代码

driver.find_element_by_xpath('//div[@class="selectArea" and not(@id="ship_to_outer")]').click()

关于python - 无法使用selenium单击div按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51700886/

相关文章:

python - 如何从 Selenium 脚本获取 Firefox Web Extension 的 "Internal UUID"?

selenium - 在哪里可以找到 Selenium Webdriver 发行说明?

javascript - 如何在机器人框架中使用 Execute Javascript 关键字来单击元素

ruby - 访问 div 元素数组中的 div 元素的属性

xml - 抓取分层数据

python - 模块在 Python 中不可调用?

python - 关于 C++ 和 python 的 tensorflow 的 Inception v3 指南

python - 交叉导入 django/python 时导入错误

python - 从 csv 文件读取 start_urls

python - 无法启动 tensorflow 2.0