【发布时间】:2017-06-27 12:16:16
【问题描述】:
我有一个从 https://www.carecredit.com/doctor-locator/ 抓取数据的小任务。 我无法使用我的脚本执行复选框勾选。
我在做
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import StaleElementReferenceException
driver = webdriver.Chrome()
driver.get('https://www.carecredit.com/doctor-locator/')
driver.find_element_by_xpath("//select[@id='dl-
profession']/option[@value='9']").click()
driver.find_element_by_xpath("//*[@id='specialty-106']").click()
并得到错误
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
driver.find_element_by_xpath("//*[@id='specialty-106']").click()
File "C:\Python27\lib\site-packages\selenium-2.46.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 70, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium-2.46.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 404, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium-2.46.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 195, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium-2.46.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 170, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: unknown error: Element <input type="checkbox" id="specialty-106" name="Specialty[]" value="106"> is not clickable at point (281, 554). Other element would receive the click: <label for="specialty-106"></label>
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7600 x86_64)
【问题讨论】:
-
你的 xpath 字符串中是否真的有换行符?当我在该页面上尝试您的 xpath 时,只要
dl-和profession之间没有空格,它似乎就可以工作。 -
您应该在帖子中加入一个问题,而不是感谢。我删除了感谢,但不确定您是否想要提问“如果我改用 perl,selenium 会遇到同样的问题吗?”或者如果你想问别的。所以我让你想出一个适当的疑问句,编辑你的帖子并添加它。