Sending a few keystrokes using selenium

How can I send multiple tabs using Selenium?

When I run:

uname = browser.find_element_by_name("text")
uname.send_keys(Keys.TAB)

the next item is selected. When executed uname.send_keys(Keys.TAB), nothing happens again - in fact, the next element is selected from uname→, so that it is the same as when it was run once.

How can I jump forward several times - mainly since I pressed TAB several times?

+7
source share
3 answers

Use action chains :

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()

Or, since this is Python, you can even do:

actions = ActionChains(browser) 
actions.send_keys(Keys.TAB * N)
actions.perform()
+16
source

I think you can also write

uname.send_keys(Keys.TAB + Keys.TAB + Keys.TAB + ... ) 

, .

+3
uname.send_keys(Keys.TAB,Keys.TAB,Keys.TAB..)

worked for me

-1
source

Source: https://habr.com/ru/post/1628669/


All Articles