简体   繁体   English

如何使用Python硒脚本将Array发送到文本框?

[英]How to send Array to a text box with Python selenium scripting?

The code which i have written to send the an array list to a text-box in my internal site. 我编写的将数组列表发送到内部站点中的文本框的代码。 Where the input to array is from excel. 数组的输入来自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:])

Format of values sending to text-box is: ['40554666', '40554539', '40554762', '40554806'] 发送到文本框的值的格式为:['40554666','40554539','40554762','40554806']

This is giving me an error because the above code is sending the values to the text-box in a wrong format where i need to remove " '' " and " [] " The Text-box can only take the numbers separated by comma or numbers in new line. 这给了我一个错误,因为上面的代码以错误的格式将值发送到文本框,其中我需要删除“”和“ []”。文本框只能使用以逗号或数字分隔的数字新行中的数字。

Note : I have tried to send one element at a time but that is not effective solution for my site. 注意:我尝试一次发送一个元素,但这对我的网站而言不是有效的解决方案。 That is the reason i am trying to send 1k values at a time. 这就是我尝试一次发送1k值的原因。

Can someone please help me here ? 有人可以帮我吗?

That's what an array of string looks like when you print the array itself in python. 这就是在python中打印字符串本身时的样子。 You need to loop through the array use one element at a time. 您需要遍历数组一次使用一个元素。

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

This prints ['1', '2', '3'] 打印['1', '2', '3']

You want 你要

for list_item in mylist:
    print(list_item)

and that prints 然后打印

1
2
3

More specifically 进一步来说

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

Side note: If all you are using is the ID, why use XPath? 旁注:如果仅使用ID,为什么要使用XPath? Just use 只需使用

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM