-1

Selenium does not find the accept cookies button.

Tested: xpath, class and css

Error

Command

import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import pandas as pd
import csv

options = Options()
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])

navegador = webdriver.Chrome(options=options)

navegador.get('https://app-vlc.hotmart.com/market/search?categoryId=25&page=1&userLanguage=PT_BR')
navegador.implicitly_wait(30)
sleep(30)
navegador.find_element(By.CSS_SELECTOR, ".cookie-policy-accept-all.hot-button.hot-button--primary").click()
navegador.implicitly_wait(30)
Andre Nevares
  • 711
  • 6
  • 21
Felipe
  • 195
  • 6
  • 1
    Does this answer your question? [How to interact with the elements within #shadow-root (open) while Clearing Browsing Data of Chrome Browser using cssSelector](https://stackoverflow.com/questions/56380091/how-to-interact-with-the-elements-within-shadow-root-open-while-clearing-brow) – HedgeHog Sep 17 '22 at 20:36

1 Answers1

0
elem=navegador.find_element(By.XPATH,"//div[@id='hotmart-cookie-policy']").shadow_root
elem.find_element(By.CSS_SELECTOR, ".cookie-policy-accept-all.hot-button.hot-button--primary").click()

You need to find the shadow root and then find from there.

Since the above didn't work try this one.

navegador.get('https://app-vlc.hotmart.com/market/search?categoryId=25&page=1&userLanguage=PT_BR')
time.sleep(10)
elem=navegador.find_element(By.XPATH,"//div[@id='hotmart-cookie-policy']")
script='''return arguments[0].shadowRoot.querySelector(".cookie-policy-accept-all.hot-button.hot-button--primary")'''
elem1= navegador.execute_script(script, elem)
elem1.click()
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32