mcburke31
mcburke31

Reputation: 3

Python Selenium chrome driver .send_keys NoneType Error

I am trying to enter a username into an input box but it is not working. The site opens and I can get it to click on the box, but not words show up. The chrome developer extensions warning popup appears. I'm still fairly new to programming. Any ideas? Thanks

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Chrome()
browser.get('https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1478123673&rver=6.7.6631.0&wp=MBI&wreply=https%3a%2f%2fwww.bing.com%2fsecure%2fPassport.aspx%3frequrl%3dhttp%253a%252f%252fwww.bing.com%252f%253fwlexpsignin%253d1&lc=1033&id=264960')
time.sleep(5)
usernameElem = browser.find_element_by_class_name('phholder').click()
usernameElem.send_keys('username')

Error

Traceback (most recent call last):
File "C:/Users/Matt/PycharmProjects/untitled/Bing.py", line 10, in <module>
usernameElem.send_keys(Keys.ENTER)
AttributeError: 'NoneType' object has no attribute 'send_keys'

Upvotes: 0

Views: 8564

Answers (2)

Lumos_lucky
Lumos_lucky

Reputation: 11

you should perform send_keys function to an element So that first assign the element to the variable usernameElem and after that click it as a function, then you will be able to send kes to the usernameElem element

usernameElem = browser.find_element_by_class_name('phholder')
usernameElem.click()
usernameElem.send_keys('username')

Upvotes: 0

thebadguy
thebadguy

Reputation: 2140

Your selector is wrong try using xpath or id:see below code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Chrome()
browser.maximize_window()
browser.get('https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1478123673&rver=6.7.6631.0&wp=MBI&wreply=https%3a%2f%2fwww.bing.com%2fsecure%2fPassport.aspx%3frequrl%3dhttp%253a%252f%252fwww.bing.com%252f%253fwlexpsignin%253d1&lc=1033&id=264960')
time.sleep(5)
usernameElem = browser.find_element_by_xpath(".//*[@id='i0116']")
#Either use above xpath or use id 
#usernameElem = browser.find_element_by_id("i0116")
usernameElem.send_keys('username')

Upvotes: 2

Related Questions