Clear text when using spy web

Hi guys, how can I clear a text box by using spy web.

I tried using Clear Text and Get Text but it is not working. I tried Set Text and place null value, same result - it did not clear the text box.

Thanks!

Saying “not working” does not tell anything about what you saw. How is it not working? Please describe what you found to others. What did you expected to see? what did you actually see?

Got it, I’m testing a log in page and first test is to try an invalid log in by entering a wrong email address on a text box, test the error message is working then I intend to clear that text box by entering the correct email address. I’m trying to use Clear text for that text box but currently it is not clearing the text box. I’m expecting to populate the text box anew and proceed with next page. All of these is via spy web.

Check that the textbox still has the same pathway after your first attempt.
You also may have to waitFor your page to refresh before you attempt to clearText. Maybe like:

WebUI.waitForElementClickable(findTestObject(...), 10)
WebUI.clearText(findTestObject(...))

WebUI.setText(findTestObject(...), "test 2 text")
WebUI.verifyElementAttributeValue(findTestObject(...), "value", "test 2 text", 10)

Any error message in the Log Viewer for this?

I tried this but it is still not working. The first text is not being cleared and the second text just sits right after the first text.

Nope, no error. The test is passing and the clear text or set text = “” is not clearing the text box

Which browser do you use? Chrome?

Could you try running your test with other type of browser?

How does WebUI.clearText() work with Firefox?

It is known that Selenium Java WebElement.clear() does not work with Chrome sometimes. Some workarounds are also known:

ooooh! I’m using Chrome. got it! I switched to Firefox and it works!

Newbie here and thanks! @kazurayam

@grylion54

1 Like