2

I am a very beginner to use Java and Selenium to write a test. I have this web element:

   <input type="number" name="yield_target" 
placeholder="Yield Target" value="0.00" min="0" step="any">

But I can not clear it by:

WebElement we =  wait.until(ExpectedConditions.visibilityOfElementLocated
(By.xpath("//input[@placeholder='Yield Target']")));
we.clear();

But I can write into it, for example if I use:

action.sendKeys(we, "223").build().perform();

it will be 0.00223 instead of 223.

5
  • I guess, when you clear your field you will see the text value of your placeholder. It does not help to clear the field because it just clear the value of the field and you will see the value of placeholder. If you don't want to see this you should remove placeholder attribute. Commented Dec 10, 2015 at 18:39
  • @CyberAleks what did you mean by "value of your placeholder"? Commented Dec 10, 2015 at 18:45
  • @CyberAleks, A DOMElement's value is independent of its placeholder attribute. Commented Dec 10, 2015 at 18:47
  • I mean, do you see "Yield Target" after clear? Commented Dec 10, 2015 at 18:47
  • @CyberAleks there is no "Yield Target", we have "0.00" in the text box Commented Dec 10, 2015 at 18:58

1 Answer 1

1

I'm not sure why we.clear() isn't working but you can clear and set in a single call (assuming that JavaScript on the page does not prevent you from using CTRL+A to select all of the contents of the number input field):

we.sendKeys(Keys.chord(Keys.CONTROL, "a"), "223");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.