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:
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:
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'
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: