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