shadownet96
shadownet96

Reputation: 1

How to find the element Name="Password" to change the value to my current password

from selenium import webdriver
from selenium.webdriver.common.by import *
from selenium.webdriver.support.ui import *
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
from lib2to3.pgen2 import driver

usernameStr = '@email.com'
passwordStr = '*******'

browser = webdriver.Chrome()
browser.get('https://ebill.nationalfuelgas.com/cgi/natfuel-bin/vortex.cgi')
browser.maximize_window()

# fill in username and hit the next button

time.sleep(3)
browser = browser.find_element_by_name("login")
browser.send_keys(usernameStr)
browser.send_keys(Keys.TAB, Keys.TAB)
time.sleep(5)

# Wait for transition then continue to fill items

I am trying to get this code figure out please help

password = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.NAME, "password")))
password.send_keys(passwordStr)
time.sleep(1)

I have tried to Tag Name, Name etc and still is not doing much every other code works but except this one.

# This code is to login the website
slogin = browser.find_element_by_name("continue" + Keys.ENTER)

Snapshot:

View Source

Upvotes: 0

Views: 55

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193108

To send a character sequence to the Email and Password field using Selenium 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://ebill.nationalfuelgas.com/cgi/natfuel-bin/vortex.cgi")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.inputfield[alt='Email']"))).send_keys("shadownet96")
    driver.find_element_by_css_selector("input.inputfield[alt='Password']").send_keys("shadownet96")
    
  • Using XPATH:

    driver.get("https://ebill.nationalfuelgas.com/cgi/natfuel-bin/vortex.cgi")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='inputfield' and @alt='Email']"))).send_keys("shadownet96")
    driver.find_element_by_xpath("//input[@class='inputfield' and @alt='Password']").send_keys("shadownet96")
    
  • 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:

ebil

Upvotes: 1

Related Questions