selenium-webdrivercss-selectorspopupwindowmouseclick-eventundetected-chromedriver

Unable to remove pop-up immediately using selenium in python


I am new to webscraping through Jupyter and want to scrape women's jackets from url only using CSS paths. I am using undetected chromedriver, when I load the url through selenium I get this pop-up discount pop-up with html code. I tried to click on the cross ('X' button) using this code:-

actions = ActionChains(browser)
wait = WebDriverWait(browser, 20)
close_button = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'btn-reset _1g4dr'))).click()

and I am getting the following error :

*TimeoutException Traceback (most recent call last) Cell In[5], line 1 ----> 1 close_button = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'btn-reset _1g4dr'))).click()

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\support\wait.py:95, in WebDriverWait.until(self, method, message) 93 if time.monotonic() > end_time: 94 break ---> 95 raise TimeoutException(message, screen, stacktrace)*

It would be great if somebody can point out the problem and suggest a workaround on it. Thank you

I have tried 'move_by_offset' method and clicked outside of the pop-up window but it did not perform the operation.


Solution

  • I couldn't replicate the precise popup that you saw. I suspect that the site has evolved since you posted this question. However, I got a similar popup (see screenshot below).

    The button to close that popup has an id attribute.

    enter image description here

    This should make selecting it easy since you just use #closeIconContainer. Hopefully other popups on the site also have an ID on this element.

    enter image description here