社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何使用python selenium脚本将数组发送到文本框?

naveen sai • 5 年前 • 1393 次点击  

我编写的用于将数组列表发送到内部站点中的文本框的代码。其中数组的输入来自excel。

value = [] // ArrayList
while len(value)<1000:
    Data=sheet.row(loop)
    T1 = Data[1].value
    T2=int(T1) // to remove float values
    T2 = str(T2) // as the text-box is only accepting the strings
    value.append(T2)
    loop += 1 //to read the next row in the excel sheet.
    driver.find_element_by_xpath('//*[@id="operand.action_(id=7)"]').send_keys(values[0:])

发送到文本框的值的格式为:['40554666','40554539','40554762','40554806']

这给了我一个错误,因为上面的代码以错误的格式将值发送到文本框,我需要删除“''”和“[%”文本框只能接受以逗号分隔的数字或新行中的数字。

注意:我试图一次发送一个元素,但这对我的网站不是有效的解决方案。这就是我一次发送1K值的原因。

有人能帮我一下吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40166
 
1393 次点击  
文章 [ 1 ]  |  最新文章 5 年前
JeffC
Reply   •   1 楼
JeffC    6 年前

这就是用python打印数组本身时字符串数组的外观。您需要一次使用一个元素遍历数组。

mylist = ['1','2','3']
print(mylist)

这张照片 ['1', '2', '3']

你想要

for list_item in mylist:
    print(list_item)

还有指纹

1
2
3

更具体地说

for list_item in mylist:
    ...
    driver.find_element_by_xpath('//*[@id="operand.action_(id=7)"]').send_keys(list_item)

附带说明:如果您使用的只是id,那么为什么要使用xpath?只使用

driver.find_element_by_id('operand.action_(id=7)')