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?

jbenfleming
  • 85
  • 3
  • 11

2 Answers2

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()

Vladimir Efimov
  • 797
  • 5
  • 13
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.

radix
  • 198
  • 1
  • 1
  • 12
  • 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' – jbenfleming Dec 08 '18 at 02:45
  • Remove this part 'obj = driver.switch_to_alert' and replace obj with driver in the following two statements and check. – radix Dec 08 '18 at 04:35
  • **Explicit wait** reference: [selenium doc](https://www.selenium.dev/documentation/en/webdriver/waits/#explicit-wait) – kaltu Dec 09 '20 at 02:28