1

I have the following code in selenium web driver :

Assert.assertEquals(emailField.getAttribute("value"), email); Assert.assertEquals(passwordField.getAttribute("value"), password);

When I inspect the element for the user name field and the password field (using firebug), I can see a "value" attribute for the user name field but not for the password field. But the code works. How is this possible?

0

1 Answer 1

1

The value is what's shown in the input field. So even if the value attribute isn't there, it implicitly has the value of what's been entered in the field.

For example, this is a Selenium regression test from their GitHub:

        [Test]
        public void CanRetrieveTheCurrentValueOfATextFormField_textArea()
        {
            driver.Url = formsPage;
            IWebElement element = driver.FindElement(By.Id("emptyTextArea"));
            Assert.AreEqual(string.Empty, element.GetAttribute("value"));
            element.SendKeys("hello world");
            Assert.AreEqual("hello world", element.GetAttribute("value"));

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.