I am trying to get rid of a cookie policy window in selenium which pops-up in the forefront of the web-page I am trying to access. Trying to close it is impossible even using Expected conditions
.
I have tried with element_to_be_clickable
and presence_of_element_located
, but none of them works.
The strange thing is that when I execute the command of closing the window 10 seconds later, it works. But then why doesn't the WebDriver wait
command work in this case ?
Another strange thing is that I don't get this cookie policy window when the selenium tab is open, only when it's reduced.
Finally, according to what I have read, presence_of_element_located
is the "longest" expected condition in order to find an element in a webpage. So I am quite blocked on that point.
The error I get is:
Traceback (most recent call last):
File "<input>", line 51, in <module>
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <a id="profilelogin" href="https://accounts.marketwatch.com/login?ifr=1&target=https%3A%2F%2Fwww.marketwatch.com%2Fwatchlist">...</a> is not clickable at point (38, 16). Other element would receive the click: <div id="cx-notification-wrapper" class="gdpr-message">...</div>
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.18.0-17-generic x86_64)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 56, in <module>
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <a id="profilelogin" href="https://accounts.marketwatch.com/login?ifr=1&target=https%3A%2F%2Fwww.marketwatch.com%2Fwatchlist">...</a> is not clickable at point (38, 16). Other element would receive the click: <div id="cx-notification-wrapper" class="gdpr-message">...</div>
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.18.0-17-generic x86_64)
So my questions are: 1) Why do I get this cookie policy window only when the tab is open 2) Why are the expected conditions and wait statements not working 3) (Eventually) How could I get my code working correctly ?
Any help would be highly appreciated. Thank you very much
My code is the following:
driver.get("https://www.marketwatch.com/watchlist")
WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.CLASS_NAME, "gdpr-close")))
driver.find_element_by_class_name('gdpr-close').click()
WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.ID, "wl-scrim-start")))
driver.find_element_by_id('wl-scrim-start').click()
WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.CLASS_NAME, "gdpr-close")))
driver.find_element_by_class_name('gdpr-close').click()
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.ID, "profilelogin")))
driver.find_element_by_id('profilelogin').click()
with:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC