无法使用selenium单击div按钮

问题描述 投票:1回答:2
I want to click a button which is actually a div tag. I am unable to click on it.
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.
python selenium web-scraping
2个回答
1
投票

正如这个截图我们告诉:

img

有4个元素,类名为selectArea。而第一个是看不见的。这就是你得到的原因:

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

因此,首先您必须准确指定要单击的元素。例如第一次下拉:

img2

有ID,可以这样找到:

driver.find_element_by_id('inventory_outer_0').click()

2
投票

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

driver.find_element_by_xpath('//div[@class="selectArea" and not(@id="ship_to_outer")]').click()
© www.soinside.com 2019 - 2024. All rights reserved.