title: Can't click a button with javascript using execute_script Selenium
body: <p><a href="https://i.stack.imgur.com/hJmtK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hJmtK.png" alt="enter image description here"></a>I'm trying to get rid of cookies popup by accepting cookies and clicking confirm. I don't have any problem with clicking an input "zgadzam się na", but clicking a button "potwierdź"seems to be impossible. My code:</p>
  
  <pre><code>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
  
  auction_url='https://www.g2a.com/grand-theft-auto-v-rockstar-key-global-i10000000788017'
  
  driver = webdriver.Chrome()
  
  
  driver.get(auction_url)
  
  add_popup = WebDriverWait(driver, 10).until(
      EC.presence_of_element_located((By.XPATH, '//*[@id="webklipper-publisher-widget-container-notification-frame"]'))
  )
  
  driver.switch_to.frame(driver.find_element_by_xpath('//*[@id="webklipper- 
  publisher-widget-container-notification-frame"]'))
  print('ads popup detected')
  time.sleep(1)
  driver.find_element_by_xpath('//*[@id="webklipper-publisher-widget- 
  container-notification-close-div"]').click()
  print('ads popup closed')
  driver.switch_to.default_content()
  
  driver.execute_script("document.querySelector('#cookies-select-all').click();")#works fine
  time.sleep(3)
  driver.execute_script("document.querySelector('body &gt; div:nth-child(76) &gt; div &gt; div &gt; div &gt; div &gt; div.modal-options__buttons &gt; button.btn.btn-primary').click();")#error
  </code></pre>
  
  <p>The error i get:</p>
  
  <pre><code>selenium.common.exceptions.WebDriverException: Message: javascript error: Cannot read property 'click' of null
  </code></pre>
  
  <p>Interestingly, when I execute this js code in browsers console, i don't get any errors</p>