Selenium Chromedriver not sending exclamation mark

Posted on

Update: The chromedriver team looked at the issues and currently they won’t fix it as it only happens with non US-en keyboards. So to fix it the computer on which chromedriver gets run must have this keyboard set for it to work without problems.

But they may implement a warning if the user doesn’t use the US-en keyboard so people won’t need to spend time debugging the issue.

package ch.robinglauser.seleniumtest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class SeleniumTest {

    public static void main(String[] args) {
        String text = "Hello World!";
        System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromdriver");
        ChromeOptions chromeOptions = new ChromeOptions();
        ChromeDriver browser = new ChromeDriver(chromeOptions);
        browser.get("https://www.robinglauser.ch/blog/search/");

        WebElement search = browser.findElement(By.cssSelector(".search-field"));
        search.sendKeys(text);

        System.out.println(search.getAttribute("value"));
        System.out.println(text);
  
System.out.println(search.getAttribute("value").equals(text));

        synchronized (browser) {
            try {
                browser.wait(1000, 100000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        browser.close();
    }
}
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
</dependencies>

You would expect the code above to print out the following:

Hello World!
Hello World!
true

But what it prints out is

Hello World
Hello World!
false

Which means that the exclamation point has gotten lost somewhere on the way after sending it via sendKeys to the driver. I’ve tested it and it’s the only sign that gets lost out of all those characters:

"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğ

There is a solution to this, but it’s not really great and won’t work for all cases:

browser.executeScript("document.getElementsByClassName('search-field')[0].value = \"" + text + "\";");

I’ve debugged the issue with wireshark to see where the exclamation mark gets lost and apparently it gets sent to the chromedriver, so the issue will be somewhere in the driver and not with the Java implementation of selenium.

I’ve opened a new issue for chromedriver and apparently there are already a few similar but not identical issues. https://bugs.chromium.org/p/chromedriver/issues/detail?id=2802

Leave a Reply