1

I am trying to web scrap and automatically fill forms in realtor website called daft.ie. When I open the page using selenium since its logs in using incognito it shows the cookies pop up everytime.

enter image description here

I wrote this code to click on this button

from selenium import webdriver
from selenium.webdriver.common.by import By

PATH = "/Users/adam/Desktop/coding/daft/chromedriver"
driver = webdriver.Chrome(PATH)
driver.implicitly_wait(10)
link1= 'https://www.daft.ie/for-rent/griffith-wood-griffith-avenue-drumcondra-dublin-9/3523580'
driver.get(link1)
driver.find_element(By.LINK_TEXT, 'ACCEPT ALL').click()

But this gives me the following error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"ACCEPT ALL"}

We can see that button exists with Accept All string, so why cant this find it? What am doing wrong here?

Also is there anyway to open the normal chrome through selenium, as if I want to fill forms after clicking on cookies button it would require me to log in using google sign in would be very hard to do, so if I can have my normal chrome open I would not need to sign in every-time I run the script.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
alex deralu
  • 569
  • 1
  • 3
  • 18

1 Answers1

0

The click on the element Accept All 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.execute("get", {'url': 'https://www.daft.ie/for-rent/griffith-wood-griffith-avenue-drumcondra-dublin-9/3523580'})
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[onclick*='acceptAll']"))).click()
    
  • Using XPATH:

    driver.execute("get", {'url': 'https://www.daft.ie/for-rent/griffith-wood-griffith-avenue-drumcondra-dublin-9/3523580'})
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[normalize-space()='Accept All']"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352