0

I ran this code to login into website of journals with my institutional access:

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 undetected_chromedriver as uc

import time
import os



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

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




driver = uc.Chrome()
driver.maximize_window()

driver.get(url)
time.sleep(5)

driver.find_element(By.CLASS_NAME,"sign-in-link").click()
time.sleep(5)
driver.find_element("tag name","a").find_element("xpath",'//*[@id="frmLogin"]/div[2]/ul/li/a').click()
time.sleep(3)
elem = driver.find_element("xpath",'//*[@id="shibboleth_search"]/div/input').send_keys("Bar-Ilan University")

but google chrome didn't pass me to the identification by password screen. I got kicked out of website , with this output on python :output. has this occured because I used undetected_chromedriver library? How do I handle this to move on to password identification screen? Thanks

Ido Kobi
  • 1
  • 1

2 Answers2

0

You can use WebDriverWait instead of sleep. Also, use By.TAG_NAME or By.CSS_SELECTOR to find element(s). And you need to use driver.forward() to use changed document page.
And instead of loading home page, just to click on button which directs you to login page, why not directly go to login page.

...
# importing action chains to scroll to element
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)

...
# waiting till email_field appears
email_field = WebDriverWait(driver, timeout=3).until(EC.presence_of_element_located((By.ID,"sign-in-link")))
actions.move_to_element(email_field).perform()
email_field.send_keys("my@email.com")
WebDriverWait(driver, timeout=3).until(EC.presence_of_element_located((By.ID,"password"))).send_keys("mypassword")
submit_btn = WebDriverWait(driver, timeout=3).until(EC.element_to_be_clickable((By.NAME,"submit")))
# scrolling to submit button just in case it isn't in view
actions.move_to_element(submit_btn).perform()
submit_btn.click()
# telling driver to use new page loaded after submitting
driver.forward()
Reyot
  • 466
  • 1
  • 3
  • 9
0

Using just Selenium, and ChromeDriver to send a character sequence within the Select your institution element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Code block:

    driver.get("https://www.tandfonline.com/loi/nvpp20")
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#cookie-accept"))).click()
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CLASS_NAME, "sign-in-link"))).click()
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//h2[text()='Log in via your institution']//following-sibling::div[2]//a"))).click()
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Type the name of your institution']"))).send_keys("Bar-Ilan University")
    
  • 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