'SendKeys does not work when computer is locked using Selenium
I use python 3.9.5 and selenium 4.1.0 with Microsoft Edge 98.0.1108.43 on Windows 10 to fill a date in a text box with the code below:
#element is the web element I want to fill
element = "element_name"
date = driver.find_element(By.ID, element)
date.click()
date.clear()
#Positionate cursor at text box beginning
for i in range(1,10):
date.send_keys(Keys.ARROW_LEFT)
#Fill the date
date.send_keys("11022022")
I use a Windows task scheduler to run a python script when the computer is locked.
This code uses to work when I am logged in and using the computer, but when it's locked the send keys fail, it used to work with edge version 95, but in recent versions stopped.
Unfortunately, I can't simply replace the value of the element, apparently, the site has some different mechanism to fill it and I must fill it with the keyboard.
<input name="element_name" type="text" value="04/02/2022" id="ctl00_ContentPlaceHolder1_dtInicial_txtData" class="edt" style="width:90px;">
I also have tried to force windows to always focus on browser windows, so the webpage always has the keyboard focus, but it also does not work.
Any hint of how to solve this question? Is it a Bug?
Solution 1:[1]
In Selenium there is a state that called headless, it allows you to work with the web page without actually "seeing" it. There is no window opening and everything works virtually. You set this state in the browser options.
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
edgeOptions.BinaryLocation =
@"C:\Program Files
(x86)\Microsoft\Edge\Application\msedge.exe";
edgeOptions.AddArgument("headless");
edgeOptions.AddArgument("disable-gpu");
var msedgedriverDir = @"E:\webdriver";
var driver =
new EdgeDriver(msedgedriverDir, edgeOptions);
In Java, there is a class called Robot which mimic keyboard pressing, so try to find the matching library in Python.
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 | Tal Angel |
