PythonPro
PythonPro

Reputation: 19

selenium with python action chains not working

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

Upvotes: 1

Views: 1773

Answers (2)

PythonPro
PythonPro

Reputation: 19

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

Upvotes: 0

Max Daroshchanka
Max Daroshchanka

Reputation: 2968

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.

Upvotes: 1

Related Questions