1

I'm writing automation script for a page in which there is a text box. The scenario is as follows:

  • I click on the text box and enter value which will throw error
  • I clear the text box and add valid value and click on confirm button
  • Then I see the answer provided in text box as an answer bubble
  • I click on the edit button to change the answer bubble back into text box
  • I clear the text box and add new value

In the last step where I need to clear and add new value to the text box, what happens is that the text box is not cleared even when the code is there to clear it. In step 2 it does clear the text box.

 public void enterElectricityReading(String electricReading) {
    WebDriverWait wait = new WebDriverWait(driver, 60);
    wait.until(ExpectedConditions.elementToBeClickable(electricityField));
    electricityField.clear();
    electricityField.sendKeys(electricReading);
}

Can someone help me to understand why does the clear code is not run and value is not cleared.

At certain period when the test is run then the clear method works. But it is not reliable.

  • Probably the fact that it becomes clickable does not automatically mean it becomes editable – Alexey R. Apr 20 '18 at 13:41
  • Where and how is electricityField defined and initialized? Is this method inside a page object? – Bill Hileman Apr 20 '18 at 13:46
  • @BillHileman Yes the method is inside the page object. It is initialized in the step definitions class. – K.K Apr 20 '18 at 13:59
  • @AlexeyR. Could you please explain what you meant if possible. – K.K Apr 20 '18 at 14:00
  • I would try creating a new instance of the page object before setting the value the second time. – Bill Hileman Apr 20 '18 at 14:07
0

Check that when you click the button, the selector is still the same and/or it is still unique. It is possible that when you clicked the button, the html may have been changed by Javascript. The element you want to interact with may have a different selector.

  • The element is not changed. It is same. – K.K Apr 22 '18 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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