发送多个带有硒的Tab键 [英] Send multiple tab key presses with selenium
本文介绍了发送多个带有硒的Tab键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Selenium发送多个标签?
How can I send multiple tabs with Selenium?
当我跑步时:
uname = browser.find_element_by_name("text")
uname.send_keys(Keys.TAB)
选择下一个元素.当再次执行uname.send_keys(Keys.TAB)
时,什么也没有发生-实际上,选择了uname
中的下一个元素->,因此它与运行一次相同.
the next element is selected. When executing uname.send_keys(Keys.TAB)
again nothing happens - actually the next element from uname
is selected -> so it is the same as when running it once.
如何多次前进-基本上就像我多次手动按TAB键一样?
How can I jump forward multiple times - basically as I would press the TAB manually multiple times?
推荐答案
使用动作链:
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
N = 5 # number of times you want to press TAB
actions = ActionChains(browser)
for _ in range(N):
actions = actions.send_keys(Keys.TAB)
actions.perform()
或者,因为这是Python,所以您甚至可以执行以下操作:
Or, since this is Python, you can even do:
actions = ActionChains(browser)
actions.send_keys(Keys.TAB * N)
actions.perform()
这篇关于发送多个带有硒的Tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文