简体   繁体   English

'WebElement' 类型的 object 没有 len() selenium python

[英]object of type 'WebElement' has no len() selenium python

I want to populate a mobile number form filed using python selenium.我想填充使用 python selenium 提交的手机号码表格。 But when I am trying to populate the mobile number form filed with a mobile number its giving me this error: TypeError: object of type 'WebElement' has no len()但是,当我尝试使用手机号码填充手机号码表单时,它给了我这个错误: TypeError: object of type 'WebElement' has no len()

Here's the portion which is giving me error:这是给我错误的部分:

# mobile number
number  = 6266644446
rs_number = driver.find_element(By.XPATH, '//*[@id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[2]/div/input')

rs_number.send_keys(rs_number)

Here's the full code:这是完整的代码:

from sre_parse import State
from tkinter.tix import Select
from selenium import webdriver

from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options

import time

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)


driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), chrome_options=chrome_options)

driver.get("https://ssg2021.in/citizenfeedback")

time.sleep(5)
# selcting states
state_select = driver.find_element(By.XPATH,'//*[@id="State"]')
drp1 = Select(state_select)

drp1.select_by_visible_text('Chhattisgarh')

time.sleep(3)


# selecting district
district_select = driver.find_element(By.XPATH,'//*[@id="District"]')
drp2 = Select(district_select)

drp2.select_by_visible_text('RAJNANDGAON')

time.sleep(3)

# selecting the age
age_num  = "22"
age = driver.find_element(By.XPATH, '//*[@id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[1]/div/div/input')

age.send_keys(age_num)

time.sleep(3)


# name
name  = "ramlal"
rs_age = driver.find_element(By.XPATH, '//*[@id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[1]/div/input')

rs_age.send_keys(name)

time.sleep(3)


# mobile number
number  = 6266644446
rs_number = driver.find_element(By.XPATH, '//*[@id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[2]/div/input')

rs_number.send_keys(rs_number)


# gender
gender = driver.find_element(By.XPATH,'//*[@id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[3]/div/select')
rs_gender = Select(gender)

drp2.select_by_visible_text('Male')

send_keys() method accepts string while you defined number as an integer.当您将number定义为 integer 时, send_keys()方法接受字符串。
So instead of所以而不是

number  = 6266644446

it should be它应该是

number  = "6266644446"

And the main problem here is that you are trying to send the web element itself with send_keys() method.这里的主要问题是您正在尝试使用send_keys()方法发送 web 元素本身。
So your code should be所以你的代码应该是

number  = "6266644446"
rs_number = driver.find_element(By.XPATH, '//*[@id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[2]/div/input')

rs_number.send_keys(number)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决 TypeError:“WebElement”类型的对象在 Python Selenium 中没有 len() - How to resolve TypeError: object of type 'WebElement' has no len() in Python Selenium WebElement 类型的 Selenium Object 没有 len() - Selenium Object of Type WebElement has no len() 类型错误:“WebElement”类型的对象没有 len() - TypeError: object of type 'WebElement' has no len() TypeError: object of type 'WebElement' has no len() error while looping for all img tags in a web page using selenium webdriver in Python? - TypeError: object of type 'WebElement' has no len() error while looping for all img tags in a web page using selenium webdriver in Python? 对于 j in range(len(columns)): TypeError: 'WebElement' 类型的对象没有 len() - for j in range(len(columns)): TypeError: object of type 'WebElement' has no len() 'float' 类型的 Python Selenium send_key object 没有 len() - Python Selenium send_key object of type 'float' has no len() TypeError:“NoneType”类型的对象在beautifulsoup & selenium Python中没有len() - TypeError: object of type 'NoneType' has no len() in beautifulsoup & selenium Python AttributeError:“ WebElement”对象没有属性(python)(硒) - AttributeError: 'WebElement' object has no attribute (python) (selenium) Python-TypeError:“单元格”类型的对象没有len() - Python - TypeError: object of type 'Cell' has no len() 类型为long的Python对象没有Len()错误? - Python object of type long has no Len() error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM