0

After running this code as part of a project, in order to enter login screen :

import pandas as pd


import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
import time
import os



output = pd.read_excel("C:\\Users\\97254\\Downloads\\output.xlsx")

url = "https://www.tandfonline.com/loi/nvpp20"


from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains


driver = webdriver.Chrome()
driver.maximize_window()

driver.get(url)


driver.find_element(By.CLASS_NAME,"sign-in-link").click()
time.sleep(5)

This screen [human verification] appeared. moreover, when the website was loaded, there was a screen asking to accept cookies [enter image description here]. Is there a selenium method dealing with these problem? Thanks

Ido Kobi
  • 1
  • 1
  • Any feedback on the [answer](https://stackoverflow.com/a/76632449/7429447) to your previous [question](https://stackoverflow.com/q/76632422/7429447) – undetected Selenium Jul 07 '23 at 21:12

1 Answers1

0

To click on the cookie element Accept 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.tandfonline.com/loi/nvpp20")
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#cookie-accept"))).click()
    
  • Using XPATH:

    driver.get("https://www.tandfonline.com/loi/nvpp20")
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='cookie-accept']"))).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
  • It worked. However, the website referred me to human verification screen - so I can't move forward to login... can I combine selenium with undetected_chromedriver library to avoid the cookie problem and being recognized as a robot ? – Ido Kobi Jul 08 '23 at 06:53
  • Yes, you can but that's a different question all together. [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – undetected Selenium Jul 08 '23 at 09:04