x 초를 기다린 후 팝업되는 "SKIP THIS AD"버튼을 클릭하고 싶은 다음 웹 사이트가 있습니다.
내 코드는 다음과 같습니다.
import selenium
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://festyy.com/wpixmC')
sleep(10)
driver.find_element_by_xpath('/html/body/div[3]/div[1]/span[5]').click()
그러나 요소를 검사 할 때 클릭 할 연결된 링크가 표시되지 않습니다. 또한
ElementClickInterceptedException: Message: element click intercepted: Element <span class="skip-btn
show" id="skip_button" style="cursor: pointer">...</span> is not clickable at point (765, 31). Other
element would receive the click: <div style="position: absolute; top: 0px; left: 0px; width: 869px;
height: 556px; z-index: 2147483647; pointer-events: auto;"></div>
어떻게 든 모든 것이 더 큰 클래스로 리디렉션되는 것 같습니다. 이것을 어떻게 극복 할 수 있습니까? xpath를 복사하려고하면 다음과 같은 내용 만 표시됩니다./div
미리 감사드립니다
수신되는 오류 ( '요소 클릭 가로 채기')는 페이지로드에 배치 된 div가 전체 페이지를 차지하여 Selenium이 건너 뛰기 버튼을 클릭하지 못하도록하기 때문인 것 같습니다.
따라서 먼저 해당 div를 제거한 다음 다음을 실행해야합니다. driver.find_element_by_xpath('/html/body/div[3]/div[1]/span[5]').click()
다음과 같이 일부 JavaScript 코드를 실행하여 div를 제거 할 수 있습니다.
driver.execute_script("""
var badDivSelector = document.evaluate('/html/body/div[7]',
document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE,
null);
if (badDivSelector) {
var badDiv = badDivSelector.singleNodeValue;
badDiv.parentNode.removeChild(badDiv);
}
""")
위의 코드는 전체 페이지 div (xpath로 식별 됨)를 찾아 페이지에서 제거합니다.
최종 코드는 다음과 같습니다.
import selenium
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get('http://festyy.com/wpixmC')
sleep(10)
driver.execute_script("""
var badDivSelector = document.evaluate('/html/body/div[7]',
document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE,
null)
if (badDivSelector) {
var badDiv = badDivSelector.singleNodeValue;
badDiv.parentNode.removeChild(badDiv);
}
""")
driver.find_element_by_xpath('/html/body/div[3]/div[1]/span[5]').click()
....
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다