Home > Software engineering >  Selenium for Python is not inputting fields
Selenium for Python is not inputting fields

Time:09-03

I'm trying to get Selenium with Python to auto login to this website, but it leaves the fields blank. I have tried to use ID's as well but it doesn't work. Any help would be appreciated!

from selenium import webdriver
from selenium.webdriver.common.by import By

username = "[email protected]"
password = "noWayJose"

url = "https://squareup.com/login"

driver = webdriver.Chrome("C:/Users/Downloads/chromedriver_win32/chromedriver")

driver.get(url)

driver.find_element_by_name("email").send_keys(username)
driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_name("sign_in_button").click()

CodePudding user response:

To send a character sequence within the Email address and Password <input> fields 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://squareup.com/login')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#email"))).send_keys("[email protected]")
    driver.find_element(By.CSS_SELECTOR, "input#password").send_keys("noWayJose")
    
  • Using XPATH:

    driver.get('https://squareup.com/login')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='email']"))).send_keys("[email protected]")
    driver.find_element(By.XPATH, "//input[@id='password']").send_keys("noWayJose")
    
  • 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:

squareup

CodePudding user response:

This might help you in this but for your information, After clicking the signin button there is a captcha. You can automate that using any captcha solving API like 2captcha or anycaptcha.

from selenium import webdriver

username = "[email protected]"
password = "noWayJose"

url = "https://squareup.com/login"

driver = webdriver.Chrome("C:/Users/Downloads/chromedriver_win32/chromedriver")

driver.get(url)

driver.implicitly_wait(10)
driver.find_element_by_id("email").send_keys(username)
driver.find_element_by_id("password").send_keys(password)
driver.find_element_by_xpath("//market-button[@id='login-standard-submit']").click()
  • Related