Selenium python-如何一次填写所有输入字段 [英] Selenium python- how can I fill all input fields at once
本文介绍了Selenium python-如何一次填写所有输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以一次填写页面上的所有字段而不是一个一个填写?
Is it possible to fill all the fields on the page at once instead of one by one?
现在我有
driver.find_element_by_id('1').send_keys(input1)
driver.find_element_by_id('2').send_keys(input2)
driver.find_element_by_id('3').send_keys(input3)
填写表格需要一段时间.
and it goes one by one taking a while to fill a form.
推荐答案
你可以在python中构造一个dict
来存储id对应的值,然后迭代填充对应的数据.
You may construct a dict
in python to store the values corresponding to id and Iterate over it to fill up the corresponding data.
input_mapping = {"1": "input1", "2": "input2", "3": "input3"}
for key, value in input_mapping.items():
driver.find_element_by_id(key).send_keys(value)
但上述方法不会是连续的.因为字典本身没有顺序.因此,如果订单真的很重要,那么使用 collections.OrderedDict()
将是更好的选择
But the above approach won't be sequential. as the dictionary maintains no order on it's own. So it would be a better choice to use collections.OrderedDict()
if the order really matters
这篇关于Selenium python-如何一次填写所有输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文