can't enter "d" "e" or "f" with sendkeys on Safari 17.3.1

83 Views Asked by At

I'm using safaridriver, included with Safari 17.3.1 (19617.2.4.11.12). I'm not having problems with the latest versions of Chrome, Edge or Firefox.

I have a web page with just a textarea input. If I try to enter "def" (either one character at a time, as part of a longer string, or just as "def") with SendKeys, the letters "d", "e" and "f" don't appear in the textarea. The html for the web page is just:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <form action="action_page.php">
      <textarea id="input" name="textInput" rows="10" cols="80">
      <textarea>
    </form>
   </body>
</html>

If I send a string with the characters "d", "e" or "f", those characters don't appear in the text input.

I've tried using just input.SendKeys(text), I've tried entering one character at a time (with or without a delay of anywhere from 100ms to two seconds) using SendKeys, and I've tried Actions to enter the text. I can enter "d" "e" or "f" when I type, but not by code. Here's the simplest of the versions I've tried:

input.Click();
input.SendKeys(""); // this seems to help in other cases, otherwise the first character doesn't appear
for (int i = 0; i < text.Length; ++i)
{
    input.SendKeys(text[i].ToString());
}

This is making me feel pretty incompetent...

1

There are 1 best solutions below

5
eternal_white On

Maybe send input using JS?

If SendKeys() doesn't work for some reason, you can use JS to do the job for you. Like this:

input.Click();
input.SendKeys(""); // this seems to help in other cases, otherwise the first character doesn't appear
for (int i = 0; i < text.Length; ++i)
{
    driver.executeScript("var e = arguments[0];e.value = e.value+\"" + text[i].ToString() + "\";",input);
}

BTW I'm not 100% sure this is valid in Java, I do it in Python and it works, maybe Java syntax will differ with Selenium here, but you got the idea.