2

I'm trying to login to my yahoo account via selenium. I'm simply learning at this point and have made programs for different websites in order to get more comfortable with Selenium overall.

I'm now trying to login to Yahoo and I haven't been able to figure it out.

URL: https://login.yahoo.com/

I've tried doing:

yahoologin1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, "#login-username"))).sendKeys("tester@yahoo.com")

yahoologin1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, "login-username"))).sendKeys("tester@yahoo.com")

yahoologin1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@id='login-username']"))).sendKeys("tester@yahoo.com")

yahoologin1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, "/html[1]/body[1]/div[2]/div[1]/div[1]/form[1]/div[2]/input[1]"))).sendKeys("tester@yahoo.com")

Anything that I'm particularly missing? Would appreciate if someone told me how to get this login to work. Rather have that than a simple copy paste of code :) Thank you!

I've done some further testing and it works when on the main tab. However, I am opening a new tab with the yahoo login page it doesn't work. Do I have to do something differently to type on a new tab?

  • What error message or unexpected result are you getting? – nofinator May 09 '19 at 21:03
  • nothing, it's as if it doesn't find it. – PuppyLover101 May 09 '19 at 21:03
  • ```try: loginYahoo = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, "/html[1]/body[1]/div[2]/div[1]/div[1]/form[1]/div[2]/input[1]"))) except TimeoutException: print("couldn't login to yahoo")``` It prints out the TimeoutException – PuppyLover101 May 09 '19 at 21:04

2 Answers2

1

I used another approach without WebDriverWait to solve, hope it helps.

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--window-size=1920x1080")
browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)

# Opening yahoo page in a new tab
browser.execute_script("window.open('https://login.yahoo.com/');")
# Switch to new tab
browser.switch_to.window(browser.window_handles[-1])
# Selecting login-username and putting email
browser.find_element_by_id('login-username').send_keys('tester@yahoo.com')

Result:

Result

Kafels
  • 3,864
  • 1
  • 15
  • 32
  • Thank you! I have actually managed to get yahoo to sign in now when I load up a blank program. However, it seems that when I open a new tab with the yahoo login page, it cannot fill it out then. Any ideas why? Doesn't selenium autofocus on the new tab? – PuppyLover101 May 09 '19 at 21:29
  • When you open a new tab, it needs be selected to selenium using `browser.switch_to.window(browser.window_handles[-1])` – Kafels May 09 '19 at 21:34
0

Here is the sample script.

url = "https://login.yahoo.com/"
# Step 1 -navigate to the AUT
driver.get(url)
print ("Step 1 - Done")
# Step 2 - Enter the username
#wait for the user name to be displayed
userName = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'input#login-username')))
userName.send_keys("used css")
# Step 3 - click on Next
driver.find_element_by_xpath("//input[@id='login-signin']").click()
# Step 4 - Enter password
passWord = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"input[name='password']")))
passWord.send_keys("password")
# Step 5 - Click on Sign in
driver.find_element_by_id("login-signin").click()

Here is how you can do the script development quick and effectively.

  • Keep a break point after browser navigated to url enter image description here
  • Get the element xpath using chrome devtools, refer here to how to get test and get the xpath
  • Go to Console > click on show python prompt to open the interactive console enter image description here
  • Enter the code here and hit enter to check if that line works when you place it in your script enter image description hereenter image description here

  • Make any necessary change and confirm the step works enter image description here

  • Copy paste the step from interactive console to script enter image description here
supputuri
  • 13,644
  • 2
  • 21
  • 39