Skip to content
Advertisement

How to login using Selenium

I have one web site like www.abc.com in this I need to add Email and press continue and in second page I need to add password and check the check box so how can I enter the password in 2nd page.

I tired with :

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
    
from selenium.webdriver.common.keys import Keys
uamId = "asas"
    
driver = webdriver.Chrome("chromedriver")
driver.get("www.abc.com")
print(driver.title)
userid = driver.find_element_by_name("P")
# fill UAM Number
userid.send_keys(a)
    
elem = driver.find_element_by_xpath('Xpath')
    
actions = ActionChains(driver)
actions.click(elem).perform()

Advertisement

Answer

Before getting the web element you have to validate the element is fully loaded and is clickable / visible.
Also in that specific site you have to click elements in order to insert the email and password.
Your code should look like this:

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

driver = webdriver.Chrome("chromedriver")
wait = WebDriverWait(driver, 20)
driver.get("www.abc.com")
print(driver.title)
#open account menu
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".navigation__menu #account span"))).click()
wait.until(EC.visibility_of_element_located((By.XPATH, "//a[text()='Sign in']"))).click()
#now you will have to switch into the iframe
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='disneyid-iframe']")))
#now you can insert the credentials
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type='email']"))).send_keys(your_email)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type='password']"))).send_keys(your_password)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement