selenium with python action chains not working

Viewed 534

I am trying to send a ALT+ESC command to my selenium chrome-driver to send it to the back of all other windows

This is the relevant code

from selenium.webdriver import Keys
from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
actions.send_keys(Keys.LEFT_ALT, Keys.ESCAPE)
actions.perform()

this is not working please help

2 Answers

To press key-combo:

from selenium.webdriver import Keys
from selenium.webdriver.common.action_chains import ActionChains

ActionChains(driver).key_down(Keys.LEFT_ALT).send_keys(Keys.ESCAPE).key_up(Keys.LEFT_ALT).perform()

But seems this is an OS-level keys combination for work with windows and this will not work in the selenium context.

Selenium actions applied to web page elements, fire some events inside browser.

ultimately I couldn't find a way to execute a OS command in selenium.

The following code has the same functionality but dose not necessarily run on the browser

from pyautogui import hotkey
hotkey('altleft', 'esc')
Related