0
DOM에있는 요소를 클릭해야하지만 페이지 하단까지 스크롤하지 않으면 브라우저 페이지에 표시되지 않습니다.Selenium webdriver에서 "요소를 클릭 할 수 없습니다"라는 오류 수정
내가 할 수있는 더 좋은 방법이 있습니까?
"메시지 : 알 수없는 오류 : 요소를 클릭 할 수 없습니다."줄이없고 scroll_browser(driver)
이 없으므로 클릭하기 전에 아래로 스크롤하면 문제가 없습니다.
import time
from selenium import webdriver
def scroll_browser(driver, destination_height=None):
# Get scroll height
if not destination_height:
destination_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == destination_height:
break
destination_height = new_height
if __name__ == '__main__':
driver = webdriver.Chrome()
driver.get('https://wikimediafoundation.org/wiki/Home')
time.sleep(2)
link = '//a[text()="Terms of Use"]'
time.sleep(2)
#scroll_browser(driver)
driver.find_element_by_xpath(link).click()
time.sleep(2)
driver.close()
당신은이 질문에 https://stackoverflow.com/questions/을 확인하실 수 있습니다 20167544/selenium-scroll-element-center-of-view – jadupl
[webdriver를 사용하여 요소 스크롤?] (https://stackoverflow.com/questions/41744368/scrolling-to-element-using-webdriver) 가능한 중복 – Mangohero1
현재 뷰포트에없는 요소를 클릭하면 chromedriver 2.30에 알려진 문제점이 있습니다. WebDriver 사양에서 말한 것처럼 현재 뷰포트에없는 요소 인 경우 웹 드라이브는 클릭/보내기 키를 보내기 전에 현재 뷰포트로 스크롤해야합니다. 따라서 각 브라우저의 Webdriver.exe는 자체 코드로 외부 코드를 추가하지 않고이를 수행해야합니다. 크롬 플레이어 버전이 2.30인지 확인하십시오. 2.32 이상으로 업그레이드하십시오. – yong