Python Selenium WebDriver等待不';无法使用cookie策略窗口的预期条件

Python Selenium WebDriver等待不';无法使用cookie策略窗口的预期条件,python,selenium,browser,conditional-statements,Python,Selenium,Browser,Conditional Statements,我试图摆脱selenium中的cookie策略窗口,它会在我试图访问的网页的最前端弹出。即使使用预期条件,也无法关闭它。 我试过使用element\u可点击和presence\u元素的位置,但都不起作用 奇怪的是,当我在10秒后执行关闭窗口的命令时,它工作了。但是在这种情况下,WebDriver wait命令为什么不起作用呢? 另一件奇怪的事情是,当selenium选项卡打开时,我没有得到这个cookie策略窗口,只有当它被减少时 最后,根据我所读到的,元素的存在是在网页中查找元素的“最长”预期

我试图摆脱selenium中的cookie策略窗口,它会在我试图访问的网页的最前端弹出。即使使用
预期条件
,也无法关闭它。 我试过使用
element\u可点击
presence\u元素的位置
,但都不起作用

奇怪的是,当我在10秒后执行关闭窗口的命令时,它工作了。但是在这种情况下,
WebDriver wait
命令为什么不起作用呢? 另一件奇怪的事情是,当selenium选项卡打开时,我没有得到这个cookie策略窗口,只有当它被减少时

最后,根据我所读到的,
元素的存在是在网页中查找元素的“最长”预期条件。所以在这一点上我被完全阻止了

我得到的错误是:

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&amp;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&amp;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)
与:

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

您正在等待cookie策略关闭按钮两次。您的代码第一次关闭cookie策略面板,因此它会一直等待按钮再次可单击,但在您关闭按钮后,它将不可单击。这就是为什么你会有例外

请尝试以下操作:

driver.get(“https://www.marketwatch.com/watchlist")
wait=WebDriverWait(驱动程序,30)
等待.直到(EC.element可点击((按.CLASS名称,“gdpr关闭”))。点击()
等待.直到(EC.element可点击((By.ID,“wl scrim start”))。点击()
等待.直到(位于((By.ID,“profilelogin”))的元素的存在。单击()
它会毫无例外地将您带到登录页面

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