Search code examples
pythonselenium-webdriverweb-scraping

Unable to login to website in Chrome using Selenium Webdriver in Python


I am using Selenium module in Python to login to the website www.value,researchonline.com..

I am able to click the button that says 'login with password' and then execute the code to input the username. But when i click on the 'Submit' button, it gives an error "Unable to process your request. Please try again.". I believe this is due to the website blocking automated script for login. Code is pasted below.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import pandas as pd
import requests
from bs4 import BeautifulSoup

# Set up the Chrome WebDriver
driver = webdriver.Chrome()

url = "https://www.valueresearchonline.com/login/?site-code=VROL&target=%2F&utm_source=home&utm_medium=vro&utm_campaign=desktop-profile-menu/"
driver.get(url)
driver.implicitly_wait(5)

# Click the button 'Login with password' (step 1)
login_button1 = driver.find_element(By.CSS_SELECTOR, "button[data-user='Log in with password']")
login_button1.click()

# Define login credentials
username = '[email protected]'
# Find the username input field and submit button (step 2)
username_field = driver.find_element(By.NAME, 'username')
# Enter the username into the field
username_field.send_keys(username)

login_button2 = driver.find_element(By.CSS_SELECTOR, "button[id='proceed-btn']")
# Submit the username to go to the password page
login_button2.click()

I have checked some related threads on stackoverflow, but most of them didn't have a solution or the proposed solution didn't work for me. Please advise if there is any workaround.

Thanks for the help.


Solution

  • I can't comment so I am going to just use the answer...

    Could you try using Undetected Chromedriver? It at least will solve the captcha when you open the website. I ran the code but I am not sure exactly what output you are looking for. If you could guide me I could try to help some more. Here is the code

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import undetected_chromedriver as uc
    import time
    import pandas as pd
    import requests
    from bs4 import BeautifulSoup
    
    
    url = "https://www.valueresearchonline.com/login/?site-code=VROL&target=%2F&utm_source=home&utm_medium=vro&utm_campaign=desktop-profile-menu/"
    
    options = uc.ChromeOptions()
    options.headless = False
    driver = uc.Chrome(options=options)
    
    driver.get(url)
    driver.implicitly_wait(5)
    
    # Click the button 'Login with password' (step 1)
    login_button1 = driver.find_element(By.CSS_SELECTOR, "button[data-user='Log in with password']")
    login_button1.click()
    
    # Define login credentials
    username = '[email protected]'
    # Find the username input field and submit button (step 2)
    username_field = driver.find_element(By.NAME, 'username')
    # Enter the username into the field
    username_field.send_keys(username)
    
    login_button2 = driver.find_element(By.CSS_SELECTOR, "button[id='proceed-btn']")
    # Submit the username to go to the password page
    login_button2.click()