4

Let's say I have this input element:

<input id="email" value="[email protected]">

I execute this piece of code:

var emailInputField = driver.FindElement(By.Id(email));
var email = emailInputField.GetAttribute("value");
emailInputField .InputField.Clear();
var empty = emailInputField.GetAttribute("value");

I would expect variable empty to be empty but it contains same text as email since I cleared the text. I realize that value attribute doesn't get synchronized with entered text, so my question is, how do I find out what text currently is in the text box?

2 Answers 2

9

Because you have already selected the element and assigned emailInputField to it then empty is going to refer to that. If you re-assign emailInputField after the clear and then get the value it should be empty. So :

var emailInputField = driver.FindElement(By.Id(email));
var email = emailInputField.GetAttribute("value");
emailInputField .InputField.Clear();
var empty = driver.FindElement(By.Id(email)).GetAttribute("value");
Sign up to request clarification or add additional context in comments.

Comments

0
var emailInputField = driver.FindElement(By.Id(email));
var email = emailInputField.GetAttribute("value");
emailInputField.InputField.Clear();
var empty = emailInputField.GetAttribute("value");

In 3rd line your making mistake, try above one

1 Comment

Sorry, I made mistake while writing this example. I edited the original post.

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.