1

On my page there is an editor that a user can type code into. It is not a normal textarea or input field. To send test to the field I use the following and it works:

Actions actions = new Actions(driver);
actions.moveToElement(locatorElement);
actions.click();
actions.sendKeys(keys);
actions.build().perform();

However, by default, the field also contains helper text "Enter your text here..." that gives validation errors if not removed i.e. the helper text is not commented out.

I have tried numerous ways to remove the text but nothing has worked. To make this trickier there is also an autocomplete feature in the editor.

  1. Use element.clear() - as mentioned this is not a visible element
  2. Click backspace multiple times - the autocomplete feature means pressing 100+ times just gives a different sentence. I don't understand why this is happening as when you use
  3. Use actions.keyDown() - this does not accept the argument Keys.RETURN

Because of the validation message, it produces it blocks a lot of tests but I'm out of ideas. Does anyone have one?

2
  • can you paste the html code snippet of the page in which you are trying to clear the textbox.
    – Alok
    Jan 13, 2018 at 3:46
  • if the element is not visible, how can you see the helper text... ' ideally this would have been implemented as a placeholder in the input tag of the element. So your question is a little ambiguous. Please clarify. Mar 13, 2018 at 15:54

2 Answers 2

1

Try using JavascriptExecutor.

import org.openqa.selenium.JavascriptExecutor;
.
.
.
.
JavascriptExecutor jse = (JavascriptExecutor) driver; 
jse.executeScript("document.getElementById('id-locator').value='';");
0
Actions actions = new Actions(driver);
actions.MoveToElement(elm);
actions.Click();
Keyboard.SendKeys("{A}",ModifierKeys.Control);
Keyboard.SendKeys("{DEL}");
actions.sendKeys(keys);
actions.build().perform();
2
  • can you explain the ModifierKeys.Control part please?
    – K-8
    Jan 12, 2018 at 16:46
  • Its just key press events for windows.
    – ChathuD
    Jan 13, 2018 at 18:48

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .