'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
Solution 1:[1]
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.
Solution 2:[2]
You can not send keys to browser before you even created the browser session and opened it.
You first have to initialize the driver, open some web page, let the page completely loaded and only then try sending these keys to the web page.
Your code could be something like this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path='chromedriver.exe')
wait = WebDriverWait(driver, 20)
actions = ActionChains(driver)
driver.get("https://www.some_url.com/")
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='some class name']")))
actions.send_keys(Keys.LEFT_ALT, Keys.ESCAPE)
actions.perform()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Max Daroshchanka |
| Solution 2 |
