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:
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 > div:nth-child(76) > div > div > div > div > div.modal-options__buttons > button.btn.btn-primary').click();")#error
The error i get:
selenium.common.exceptions.WebDriverException: Message: javascript error: Cannot read property 'click' of null
Interestingly, when I execute this js code in browsers console, i don't get any errors