2

I am working on some automation tests and have gotten to a wall. When the page is loaded, a call is made to get data to prefill input fields from what I can tell.

Here is the element that I'm checking(Goal is get the prefilled text from the input type="text" name="tempname" to validate it is correct):

<div class="twelve columns">
          <label for="tempname">Template Name <span class="compulsion"> *</span></label>
          <input type="text" name="tempname" id="tempname">
          <h4 class="notice fielderror"></h4>
</div>

Typically in my Selenium test, I would return the element and use getAttribute() or getText() to return what I'm looking for and use an assertTrue or assertEquals.

I can't figure out how to get the text that is displayed within this element to validate it. Any ideas/tips would be really helpful!

Side note: I am using Selenium for my automation tests

1 Answer 1

2

Can you please try this approach?

element = FindElement(By.CssSelector("input[id='tempname']"))
string = element.getAttribute("value")

This string should have what you want.

2
  • Ahh thank you for this! .getAttribute("value") seemed to be exactly what I was looking for. Since this element doesn't have a value= attribute, why does it return correctly?
    – Jordan
    Commented Jul 25, 2016 at 23:15
  • @Jordan, look it up on the internet, "value" is hidden
    – Yu Zhang
    Commented Jul 25, 2016 at 23:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.