WebElement 类型的 Selenium 对象没有 len() [英] Selenium Object of Type WebElement has no len()

查看:72
本文介绍了WebElement 类型的 Selenium 对象没有 len()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Selenium 登录 Facebook Marketplace.电子邮件地址正在按预期填充.密码字段未被识别.

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

错误:

文件C:\Users\jsmith\fb.py",第 18 行,在password.send_keys(密码)类型错误:WebElement"类型的对象没有 len()

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

我的代码:

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)

除了上面的 xpath 之外,我还尝试使用 find_element_by_name()find_element_by_id()(以及两者的复数).

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

推荐答案

您有 2 个名为 password 的变量,因此当您尝试将密码字符串发送给您输入时,它不起作用

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

这篇关于WebElement 类型的 Selenium 对象没有 len()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆