在使用Selenium 进行抓取网页的时候,对网页中 按钮或者超链接 进行点击的时候,往往会遇到下列问题:
Traceback (most recent call last):
File "F:/Python_work/PyReview/jnta.py", line 24, in
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, u'下一页'))).click()
File "E:\Python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 77, in click
self._execute(Command.CLICK_ELEMENT)
File "E:\Python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 493, in _execute
return self._parent.execute(command, params)
File "E:\Python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "E:\Python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element ... is not clickable at point (913, 578). Other element would receive the click:
(Session info: chrome=62.0.3202.75)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.14393 x86_64)
造成的原因是 标签被隐藏
解决方法很简单,在点击之前让 该链接显示即可:
page = driver.find_element_by_partial_link_text(u'下一页') driver.execute_script("arguments[0].scrollIntoView(true);", page) #加上这一句即可 WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, u'下一页'))).click()