1

I am trying to access and login to the following webpage using Selenium in Python:

'http://games.espn.com/ffl/leagueoffice?leagueId=579054&seasonId=2018'

When the page is accessed a pop up window appears asking for the user's credentials. The below code is what I have so far.

import time
from selenium import webdriver

user = 'test_user'
pw = '*********'

url = 'http://games.espn.com/ffl/leagueoffice?leagueId=579054&seasonId=2018'

driver = webdriver.Chrome("C:\\Users\\abc\\Downloads\\chromedriver\\chromedriver.exe")

driver.get(url)

obj = driver.switch_to_alert

time.sleep(5)

obj.find_element_by_name('email').send_keys(user)
obj.find_element_by_name('password').send_keys(pw)

When I run it I receive this error:

AttributeError: 'function' object has no attribute 'find_element_by_name'

Based on other stackoverflow threads I thought I was approaching this correctly. Could anyone help me on this?

3
  • Are you missing a function call? Like driver.switch_to_alert()? Commented Dec 8, 2018 at 0:42
  • Trying that gave me: 'NoAlertPresentException: no alert open' Commented Dec 8, 2018 at 0:50
  • Consider replacing the error message above with the new one. Commented Dec 8, 2018 at 0:52

2 Answers 2

3

Elemets you're trying to interact with are located in another frame. Using inspector you can see that they are inside <iframe id="disneyid-iframe" name="disneyid-iframe"

So before doing any actions, you need to switch to that frame:

driver.switch_to_frame("disneyid-iframe")

and then do what you need (note: I corrected locators to use type attribute since I didn't see that elements have name attribute)

driver.find_element_by_css_selector("input[type = 'email']").send_keys(user)
driver.find_element_by_css_selector("input[type = 'password']").send_keys(pw)

Remember to switch back to default context after you are done interacting with elements from that frame:

driver.switch_to.default_content()

Sign up to request clarification or add additional context in comments.

Comments

0

Try this and Check:

obj.find_element_by_xpath('//input[@type="email"]').send_keys(user)
obj.find_element_by_xpath('//input[@type="password"]').send_keys(user)

Also don't use time.sleep() module in selenium,keep a habit of using explicit waits.

3 Comments

Can you elaborate on using explicit waits? And with your solution I receive the follwing:'NoAlertPresentException: no alert open', which I take to mean that the pop up login menu is not considered an 'alert'
Remove this part 'obj = driver.switch_to_alert' and replace obj with driver in the following two statements and check.
Explicit wait reference: selenium doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.