0

I am not able to accept the cookie button it is always showing me error as:

AttributeError: 'NoneType' object has no attribute 'click'

Also my browser is getting closed automatically.

Snapshot of the code and error:

Code Image

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Post your code and error message as text, not images. See [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/). – AlexK Feb 10 '23 at 01:54

1 Answers1

0

The line of code you have used:

cookie_accept = driver.find_element(by=By.LINK_TEXT, value="Sign in")

doesn't identify any element within the HTML DOM. Hence cookie_accept remains NULL. So you can't invoke click on the NULL object and you see the error:

AttributeError: 'NoneType' object has no attribute 'click'

Solution

The desired element is a dynamic element, so to click on the clickable element 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://hub.knime.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.accept-button.button.primary"))).click()
    
  • Using XPATH:

    driver.get('https://hub.knime.com/')  
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(., 'login or register')]"))).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:

knime

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