nafcb10
nafcb10

Reputation: 33

Send Keys shift+tab on Selenium Web driver

I'm trying to get Selenium to perform SHIFT + TAB (goes to top of page) but the code is not working. Am using Python and am quite new to Selenium

Package imported -

import selenium.webdriver as webdriver    
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.action_chains import ActionChains    
from selenium.webdriver.common.keys import Keys

Code that I've tried:

 ActionChains(driver)
 key_down(Keys.SHIFT+Keys.TAB)
send_keys(Keys.SHIFT,Keys.TAB)

I expect the page to go to the top with SHIFT+TAB

Upvotes: 3

Views: 8840

Answers (2)

V-cash
V-cash

Reputation: 368

if you want to shift tab use:

driver.switch_to.window(driver.window_handles[1])

[1] means shift to 2º window, Nº0 = is the first

Upvotes: 1

John Gordon
John Gordon

Reputation: 33359

Shamelessly copied from https://www.programcreek.com/python/example/97717/selenium.webdriver.common.keys.Keys.SHIFT

a = ActionChains(driver)
a.key_down(Keys.SHIFT).send_keys(Keys.TAB).key_up(Keys.SHIFT)
a.perform()

Upvotes: 8

Related Questions