Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

python - Selenium Object of Type WebElement has no len()

I'm trying to log into Facebook Marketplace from Selenium. The email address is populating as expected. The password field is not being recognized.

The error:

File "C:Usersjsmithfb.py", line 18, in password.send_keys(password) TypeError: object of type 'WebElement' has no len()

My code:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
import time

username = 'myemail'
password = 'mypassword'
#OpenBrowser
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://facebook.com/")

#Logging
email = driver.find_element_by_id('email')
password = driver.find_element_by_xpath('//*[@id="pass"]')
#facebook username input
email.send_keys(username)
#facebook password input
password.send_keys(password)

I have tried using find_element_by_name() and find_element_by_id() (and the plural of both) in addition to the xpath above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have 2 variables named password, so when you try to send you password string to input, it won't work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...