0

I have 6 selenium tests (TestNG) running on chrome and firefox (both up to date versions) which connect to Browser stack to run.

the problem is that 1 of the test fails intermittently on Chrome as the sendKeys method is entering the email twice after clearing the text field. (i have seen that field gets cleared successfully in the test run)

problem - value entered twice: [email protected]@test.com.

the tests run on gocd (like Jenkins) every morning. it only fails when run on gocd but when testing on my intellij these tests are always passing.

this is my code to clear and send the text

 private void editTextField(String textToInput, WebElement element) {
            element.clear();
            element.sendKeys(textToInput);
    }

        public void editPassengerDetails(String name, String lname, String email) {
        waitForPageCheckOutPageToLoad();

        openPassengerDetailsBox.click();

        editTextField(name, emailFirstName);

        editTextField(lname, emailLastName);

        editTextField(email, emailAddress);
}

test

checkoutPage.editPassengerDetails("Testfnames", "Testlname", "[email protected]");

can someone see anything wrong with this?

4 Answers 4

1

Make sure that before sending the text,filed is clearing properly. add assert before sendkeys to make sure that text field is empty

1

According to you statement, it looks like clear fails to clear field. Can you try to add following code into the automation to clear up field and test it with it?

static String getValueFromElement(WebElement locator) {
        return tryFindElement(locator).getAttribute("value")
    }

This method above will return you the what's written in the element.

static def retailPriceInputFieldCleaner(By locator) {
    WebElement inputFieldAsElement = tryFindElement(locator)
    getValueFromElement(inputFieldAsElement).length().times {
        inputFieldAsElement.sendKeys(Keys.BACK_SPACE)
    }
    this
}

And this one above will press backspace for each key written in the textbox. It's written in groovy but you can adapt it easyly to any language I guess.

And if it's possible please share the test case's itself since knowing how your method used would be useful for troubleshooting.

1
  • @Fenomenoq is this answer solves your problem?
    – TuRQuaS3
    Commented Nov 18, 2019 at 10:58
1

i raised a similar protractor issue on this , the issue seems like

  1. if you give a input say "one" to textbox 'A'
  2. then you clear text box 'A'
  3. and then sends input to textbox 'B'
  4. and then sends input say "two" again to textbox 'A', A will get the value onetwo

If you immediately use sendKeys after using clear() , everything works fine.

  1. if you give an input say "one" to textbox 'A'
  2. then you clear text box 'A'
  3. and then sends input say "two" again to textbox 'A', A will get the value two

In my case using the element in order fixed the issue

link to issue:

https://github.com/angular/protractor/issues/5370

0

Try this for Appium

driver.getKeyboard().sendKeys("");
1
  • 1
    Could you elaborate on what this is intended to do?
    – corsiKa
    Commented Jun 29, 2021 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.