Send multiple tab key presses with Selenium

As the OP states: "actually the next element from uname is selected".

After the first <TAB> key you have moved off the element, so no further <TAB>s will be recognized by that element. You need to locate the parent element and send keys to it.


I think you can also write

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

It may be useful if you have only two or three commands to send.


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