0

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'

2 Answers 2

2

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')
Sign up to request clarification or add additional context in comments.

1 Comment

The find_element_by_id worked. Thank you for your help, I was trying to figure this out for hours. Thanks again
0

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

Comments

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.