Reputation: 53
I am trying to accept the cookies in airbnb home page. But I can't find the "key" to get it. Find below my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep
options = Options()
# options.add_argument('--headless')
options.add_argument('window-size=400,800')
navegador = webdriver.Chrome(options=options)
navegador.get('https://www.airbnb.com/')
# I tried this 02 ways
WebDriverWait(navegador, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ""))).click()
WebDriverWait(navegador, 10).until(EC.element_to_be_clickable((By.XPATH, ""))).click()
Find below the HTML from Airbnb
<button class="optanon-allow-all accept-cookies-button" title="OK" aria-label="OK" onclick="Optanon.TriggerGoogleAnalyticsEvent('OneTrust Cookie Consent', 'Banner Accept Cookies');" tabindex="1">OK</button>
Upvotes: 1
Views: 542
Reputation: 29362
from my end I could see this HTML in airbnb :
<button data-testid="accept-btn" type="button" class="_1xiwgrva">OK</button>
you can click on the accept cookies button like this :
WebDriverWait(navegador, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-testid='accept-btn']"))).click()
But I see, you have shared this html :-
<button class="optanon-allow-all accept-cookies-button" title="OK" aria-label="OK" onclick="Optanon.TriggerGoogleAnalyticsEvent('OneTrust Cookie Consent', 'Banner Accept Cookies');" tabindex="1">OK</button>
in this case, you could use the below code :
WebDriverWait(navegador, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.optanon-allow-all.accept-cookies-button"))).click()
Upvotes: 1
Reputation: 33361
Try this:
WebDriverWait(navegador, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button.accept-cookies-button"))).click()
Also, I don't understand why are you defining so small screen size?
We are normally use
options.add_argument('--window-size=1920,1080')
Also, it should be --
there as I used here
Upvotes: 1