Winium.Desktop icon indicating copy to clipboard operation
Winium.Desktop copied to clipboard

SendKeys is not working in java winium desktop driver.

Open truptibhatt opened this issue 6 years ago • 6 comments

I have tried following code

driver.findElement(By.id("txtSearchFields")).sendKeys(Keys.ENTER); Even i tried driver.findElement(By.id("txtSearchFields")).sendKeys("{ENTER}");

also tried WebElement player = driver.findElement(locator1); Actions act= new Actions(driver);

			 act.click(player).sendKeys(player,Keys.ENTER).build().perform();

How can i press shift plus tab using java winium? Robot class is randomly pressing key, not as per my sequence. Any help is really appreciated @skyline-gleb

truptibhatt avatar Oct 08 '18 04:10 truptibhatt

@heilwood and @SharonJacob- I have used following code:

DesktopOptions option = new DesktopOptions();
		 
		option.setApplicationPath("C:\\Program Files\\Microsoft Office 15\\root\\office15\\excel.exe");
		option.setKeyboardSimulator(KeyboardSimulatorType.BasedOnWindowsFormsSendKeysClass);

        WiniumDriverService service = new WiniumDriverService.Builder().usingDriverExecutable(new File("driver/Winium.Desktop.Driver.exe"))
            .usingPort(9999)
            .withVerbose(true)
            .withSilent(false)
            .buildDesktopService();
     
        WiniumDriver driver = new WiniumDriver(service, option);

 Actions act= new Actions(driver);				
					
				 act.sendKeys(Keys.TAB).build().perform();
				 act.sendKeys(Keys.ENTER).build().perform();

But cant i use following to send keys from one element???

 WebElement player1 = driver.findElement(locator2);
player1.sendKeys(player1,Keys.Tab)

truptibhatt avatar Oct 12 '18 08:10 truptibhatt

@truptibhatt first thing that .build() reiquired when you have actions chain. for example:

 act.sendKeys(Keys.TAB).sendKeys(Keys.ENTER).build().perform();

if you have only one action you can use just perform();

I'm not sure that i understand your question, but you can send keys to elements like that;

 Actions act= new Actions(driver);				
 WebElement player1 = driver.findElement(locator2);			
 act.sendKeys(player1, Keys.TAB).sendKeys(player1, Keys.ENTER).build().perform();

If you would like to press and hold one button you should write like that (but this is implemented only in my version of driver):

 Actions.KeyDown(Keys.Control).sendKeys(elem,Keys.ENTER).KeyUp(Keys.Control).build().perform();

heilwood avatar Oct 12 '18 08:10 heilwood

@heilwood -Ok so Action class is the option. Thanks a lot. It was a great help. One more thing, can you suggest what should we use for dynamically wait for element? what is the best approach in winium java to wait for element to be present?

truptibhatt avatar Oct 12 '18 10:10 truptibhatt

This is c# code, but it will be easy to adopt to java, we are using standart selenium wait:

    protected void WaitUntilElementIsVisible(By locator)
    {
        var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
        try
        {
            wait.Until(driver => driver.FindElement(locator).Displayed);
        }
        catch (WebDriverTimeoutException)
        {
            throw new WebDriverTimeoutException($"Element is not displayed {@locator}");
        }
    }

heilwood avatar Oct 12 '18 12:10 heilwood

@heilwood can I get some help on how to make Actions class to work with combination of KeyDown and SendKeys for example something like this Actions.KeyDown(Keys.Control).SendKeys("L").KeyUp(Keys.Control).build().perform();

shivalkar avatar Aug 27 '19 10:08 shivalkar

Please let me know if this would be of help

sindhua25 avatar Aug 12 '20 22:08 sindhua25