Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Seleniu发送类型为';浮动';没有len()_Python_Selenium - Fatal编程技术网

Python Seleniu发送类型为';浮动';没有len()

Python Seleniu发送类型为';浮动';没有len(),python,selenium,Python,Selenium,我试图从excel中的一列发送搜索栏上的键,它以前工作正常,但现在只返回错误:“float”类型的对象没有len() 请查找代码: def search(key): driver.get(url) driver.find_element_by_xpath('//*[@id="searchCode"]').clear() driver.implicitly_wait(10) driver.find_element_by_xpath('//*[@i

我试图从excel中的一列发送搜索栏上的键,它以前工作正常,但现在只返回错误:“float”类型的对象没有len()

请查找代码:

def search(key):
    driver.get(url)
    driver.find_element_by_xpath('//*[@id="searchCode"]').clear()
    driver.implicitly_wait(10)
    driver.find_element_by_xpath('//*[@id="searchCode"]').send_keys(key)
def get_keyword():
    data = pd.read_excel('search.xlsx')
    for d in data['code']:
        search(d)
如果我改为:

def search(key):
    driver.get(url)
    driver.find_element_by_xpath('//*[@id="searchCode"]').clear()
    driver.implicitly_wait(10)
    driver.find_element_by_xpath('//*[@id="searchCode"]').send_keys(str(key))
def get_keyword():
    data = pd.read_excel('search.xlsx')
    for d in data['code']:
        search(d)
然后搜索栏出现:175717.0,但在excel中,它只有175717和测试格式,有点混乱

Excel:(非常确定没有浮点值,我已经转换成文本格式了。)

code
175717
175740


请有人帮忙,谢谢!

据Selenium报道

send_key
接受
str
而不是
float
因此,在您的情况下,您将用
str(d)
发生错误的原因是
返回对象中的项数,该项数对于
浮点值无效

您可以发布更多的代码吗,比如您在
搜索
下实现的代码?您好,我已经向搜索功能添加了代码,谢谢!您好,谢谢,但是当它转换为str时,会出现175717.0,不确定为什么在excel中,它是一个整数。根据您的错误当您在data['code']下迭代元素时,您似乎以浮点结束,您可以先将其转换为
int
然后将其转换为stringOk,我会尝试,谢谢!
send_keys(*value)[source]
    Simulates typing into the element.
    Args :  
        value - A string for typing, or setting form fields. For setting file inputs, this could be a local file path.