0

Hello I am using a automated web scraper but at random times the screen is covered with an accept cookies popup that blocks the form click button. It affects the whole script and I don't know how I could write and if cookie_pop_up.close() or something of that nature. Get the xpath of the close for cookies?

I am trying to log into snapchat here is my code:

hrome_options = webdriver.ChromeOptions()
                chrome_options.add_argument(f"--proxy-server=http://{random.choice(live_proxies)}")
                driver = webdriver.Chrome("chromedriver.exe", options=chrome_options)
                driver.set_window_position(-10000,0)
                driver.get("https://accounts.snapchat.com/accounts/login")
                if "Log in to Snapchat" in driver.page_source:
                    proxy_is_valid = True
                    user_input = driver.find_element_by_id("username")
                    user_input.send_keys(user)

                    passsword_input = driver.find_element_by_id("password")
                    passsword_input.send_keys(password)

                    login_button = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/article/div[1]/div/form/div[4]/button")
                    login_button.click()
                    if check_for_captcha_connectivity(driver):

                        solve(driver)

Here is the error:

File "C:\Users\Administrator\Desktop\python\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Administrator\Desktop\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Administrator\Desktop\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button type="submit" class="btn btn-lg btn-primary">...</button> is not clickable at point (507, 384). Other element would receive the click: <div class="cookie-popup">...</div>
  (Session info: chrome=77.0.3865.75)

HERE IS WHAT IT LOOKS LIKE THAT BLOCKS IT FROM LOGIN: https://imgur.com/gallery/sZroFq9

thanks in advance!

update I tried this

login_button = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/article/div[1]/div/form/div[4]/button")
                    login_button.click()
                    if ElementClickInterceptedException:
                        time.sleep(1)
                        driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/div/div/div[3]/div[4]").click()
                        continue

still failed the indents pasted weirdly ^

Dan
  • 31
  • 2

1 Answers1

1

You need to agree to the cookies consent first and then proceed. To accept the cookie consent you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.cookie-popup"))).click()
    driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/article/div[1]/div/form/div[4]/button").click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='cookie-popup']"))).click()
    driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/article/div[1]/div/form/div[4]/button").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
  • I added this code before it clicks the submit button but now it seems to just stop and not even close the cookies. Do you have discord where I can send you my code sir, I'll pay a bit if you can fix this issue. – Dan Aug 10 '20 at 23:58
  • @DanC Can you update the question with some more details and update me please? – undetected Selenium Aug 11 '20 at 00:06
  • I added a image of what's stopping and causing the error I think and the code I am using to simulate a login – Dan Aug 11 '20 at 00:19