Selenium sendKeys are not sending all characters

前端 未结 7 1697
面向向阳花
面向向阳花 2021-02-02 15:29

I\'m using Java, Selenium, and Chrome for test automation. Our developers recently upgraded our UI from AngularJS to Angular2 (not sure if that matters). But since then, sendKey

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 16:16

    Using

    • Chromium 78.0.3904.70,
    • Vaadin Flow Framework 14.1.3,
    • Selenium 3.141.59
    • and OpenJDK 11.0.5

    the behavior also occurs and is even worse: I see that the character is typed in and suddenly after that it disappears. A workaround is to be persistent and just try it again. And again. Until the character is finally typed in.

        // Type in every single character
        for (int i = 0; i < textToType.length(); i++) {
            boolean typingCharacterWasSuccessful = false;
            // If typing was not successful before, just type again
            while (!typingCharacterWasSuccessful) {
                // Type in the character
                char singleCharacterToType = textToType.charAt(i);
                htmlTextfeld.sendKeys(Character.toString(singleCharacterToType));
                // Wait a little. Maybe alternatively/additionally wait.until(...)
                Thread.sleep(200);
                // Check typed in string.
                String inputValueAfterTyping = htmlTextfeld.getAttribute("value");
                if (inputValueAfterTyping.length() > i + 1) {
                    // Alternatively: delete everything and start all over
                    throw new Exception("Input value too long. Maybe character typed in twice!?");
                }
                // Typing was successful if the value in the input field is as expected (up to now)
                typingCharacterWasSuccessful
                        = inputValueAfterTyping.equals(textToType.substring(0, i + 1));
            }
        }
    

提交回复
热议问题