0

How can I send Data in desktop application if sendKeys() is not working fine but element is visible and on for the same xpath click action is working fine, but unable to send data.can anyone please help me on that

driver.findELement(By.name("")).sendKeys("") // isn't working xpath is same driver.findELement(By.name("")).click() // working xpath is same

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 09 '23 at 10:45
  • Actually i am working on a desktop application where i need to login so i need to send some input but sendkeys is not working but the element is visible as also clickable but while using sendkeys for sending input its not working – yogesh ghildiyal Jan 09 '23 at 15:37

1 Answers1

0

You can try to use the next approaches, in this case, to paste text on Java or C#:

using Selenium Send Keys C#

public void PasteText(IWebElement element, string text)
{
    Clipboard.SetText(text);
    element.Click();
    Thread.Sleep(100);
    element.SendKeys(OpenQA.Selenium.Keys.Control + "a" + OpenQA.Selenium.Keys.Delete);
    Thread.Sleep(100);
    element.SendKeys(OpenQA.Selenium.Keys.Control + "v");
}

using Selenium Send Keys Java

public void pasteText(WebElement element, String text)
{
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection stringSelection = new StringSelection(text);
    clipboard.setContents(stringSelection, null);       
    element.click();
    Thread.sleep(100);
    element.sendKeys(Keys.chord(Keys.CONTROL, "a"));
    element.sendKeys(Keys.Delete);
    Thread.sleep(100);
    element.sendKeys(Keys.chord(Keys.CONTROL, "v"));
}

using InputSimulator library C#

public static void PasteText(IWebElement element, string text)
{
    Clipboard.SetText(text);
    element.Click();
    Thread.Sleep(100);
    var inSim = new WindowsInput.InputSimulator();
    inSim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_A);      
    inSim.Keyboard.KeyDown(VirtualKeyCode.DELETE);
    Thread.Sleep(100);
    inSim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_V);
    inSim.Keyboard.KeyDown(VirtualKeyCode.RETURN);
}

using Robot library Java

public void pasteText(WebElement element, String text)
{
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection stringSelection = new StringSelection(text);
    clipboard.setContents(stringSelection, null);               
    element.click();
    Thread.sleep(100);
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_DELETE);
    robot.keyRelease(KeyEvent.VK_DELETE);
    Thread.sleep(100);
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_RETURN);
    robot.keyRelease(KeyEvent.VK_RETURN);
}
G. Victor
  • 545
  • 1
  • 6
  • 17