0

I have been trying to scrape some information of this website with selenium. However when I access the website it need to accept cookies to continue and it seems it is Java script.

Does anyone know how to get around this? or which topic should i focus on?

from selenium import webdriver
browser = webdriver.Chrome()

browser.get("https://www.giffgaff.com")

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Vicent
  • 1
  • 1
  • 1

2 Answers2

0

I am currently on android mobile so I can't use DevTools.

First you can right click the "Accept All cookies" button and Click Inspect and then copy the XPath.

Now try this:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,''))).click()

Replace the empty string with the XPath, or you can adjust the wait.

Wasif
  • 14,755
  • 3
  • 14
  • 34
0

To click on Accept all cookies you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://www.giffgaff.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.cbot-btn__switch"))).click()
    
  • Using XPATH:

    driver.get('https://www.giffgaff.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='trynow']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

giffgaff

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352