1

I have the following website where I want to click on the button "SKIP THIS AD" that popup after waiting x seconds.

enter image description here

My code is as follows:

 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()

However, when I inspect the element I don't see a connected link to be clicked. In addition, I get

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>

Somehow it seems that everything is redirected to the larger class? How can I overcome this? When I try to copy the xpath I get also only the following: /div

Thanks in advance

2
  • It seems like the click event is programmatically detected on that div. After you click about twice (after ads pop up), the JavaScript code for the redirect is activated. This means that there is no hard <a> link in the HTML itself. Commented Jan 9, 2020 at 21:19
  • Could it be because there is an alert on screen? Commented Jan 9, 2020 at 22:28

1 Answer 1

2

It seems that the error that you receive ('element click intercepted') is due to the fact that there is a div that is placed on page load, that takes up the whole page, preventing Selenium from clicking on the skip button.

Therefore you have to remove that div first and then run this: driver.find_element_by_xpath('/html/body/div[3]/div[1]/span[5]').click()

You can remove the div by running some JavaScript code as follows:

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);
}
""")

The code above finds the full page div (identified by xpath) and removes it from the page.

Your final code should look something like this:

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()

....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.