title: Handling "Accept Cookies" popup with Selenium in Python
body: <p>I've been trying to scrape some information of this real estate website with selenium. However when I access the website I need to accept cookies to continue. This only happens when the bot accesses the website, not when I do it manually. When I try to find the corresponding element either by xpath or id, as I find it when I inspect the page manually I get following error.</p>
  <p>selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {&quot;method&quot;:&quot;xpath&quot;,&quot;selector&quot;:&quot;//*[@id=&quot;uc-btn-accept-banner&quot;]&quot;}</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.support import expected_conditions as EC
  
  
  
  PATH = &quot;/usr/bin/chromedriver&quot;
  driver = webdriver.Chrome(PATH)
  
  driver.get(&quot;https://www.immoweb.be/en/search/house/for-sale?countries=BE&amp;page=1&amp;orderBy=relevance&quot;)
  driver.find_element_by_xpath('//*[@id=&quot;uc-btn-accept-banner&quot;]').click()
  
  </code></pre>
  <p>Does anyone know how to get around this? Why can't I find the element?</p>
  <p>Below is an image of the accept cookies popup.</p>
  <p><a href="https://i.stack.imgur.com/VQE53.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VQE53.png" alt="enter image description here" /></a></p>
  <p>This is the HTML corresponding to the button &quot;Keep browsing&quot;. The XPATH is as above.</p>
  <pre><code>&lt;button aria-label=&quot;Keep browsing&quot; id=&quot;uc-btn-accept-banner&quot; class=&quot;uc-btn-new  uc-btn-accept&quot;&gt;Keep browsing
            &lt;span id=&quot;uc-optin-timer-display&quot;&gt;&lt;/span&gt;&lt;/button&gt;
  </code></pre>