title: Why does Selenium not click the desired button in Chrome headless mode?
body: <p>I have the following Python script who's purpose is to copy the entire Contract Source Code from <a href="https://bscscan.com/address/0xf811e41dc5271814ceb9aaf4f148478d5c6a0134#code" rel="nofollow noreferrer">https://bscscan.com/address/0xf811e41dc5271814ceb9aaf4f148478d5c6a0134#code</a> using the &quot;Copy source code to clipboard&quot; button, located below the &quot;Outline&quot; and &quot;More Options&quot; buttons.</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.common.by import By
  from selenium.webdriver.support import expected_conditions as EC
  
  options = webdriver.ChromeOptions()
  options.add_argument(&quot;--headless&quot;)
  driver = webdriver.Chrome(options=options)
  
  driver.get('https://bscscan.com/address/0xf811e41dc5271814ceb9aaf4f148478d5c6a0134#code')
  
  WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[2]/div/div/div/button'))).click()
  WebDriverWait(driver, 20).until(
      EC.element_to_be_clickable(
          (By.XPATH, '/html/body/div[1]/main/div[4]/div[3]/div[2]/div/div[7]/div[2]/div[2]/div[1]/div[2]/span/a[1]')
      )
  ).click()
  
  driver.quit()
  </code></pre>
  <p><code>WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[2]/div/div/div/button'))).click()</code>
  is used to click an &quot;allow cookies&quot; pop-up which blocks the button I want when the page opens.</p>
  <p>When running in headless mode, which is enabled using <code>options.add_argument(&quot;--headless&quot;)</code> I don't get an error but the text is not copied. When I comment out <code>options.add_argument(&quot;--headless&quot;)</code> and run the code with the normal window, the text is copied.</p>
  <p>I plan to run this script in the background to scrape contract information from multiple cryptocurrency tokens, so being able to run it in headless mode is important.</p>