Getting value from text input field

Asked by Jason Dunckley on 2013-01-16

Firstly, thanks for publishing this framework, it has a great amount of boilerplate functionality (like reporting/shared library) that is needed for a good test framework, and seems to work very well.

I am wanting to get back the value="" value for a text input field. Getting the element is no problem, however using get_element_source does not return anything (empty string).

I have successfully used the get_element_source for a div and then parsed the contents using regEx, however in this case the div contains many input fields, and it seems like it would be better (at least for me, in this case) to manage getting/setting values as individual elements rather than having to parse the value data out of the div for a getter, and then map that to the individual text field elements for the setter (write_textfield()).

e.g.

<div class="column">
<label>
                First Name:
<input type="text" value="Johnny" name="FirstName"/>
</label>
<!--many more of these label/input field pairs in this div-->
</div>

This may boil down to a limitation in the structure of the HTML and/or WebDriver, however I thought WebDriver could handle this case on it's own like in actions.py's assert_text_contains() which calls _get_text(elem).

Thanks in advance for any suggestions/patches.

-Jason

Question information

Language:
English Edit question
Status:
Solved
For:
selenium-simple-test Edit question
Assignee:
No assignee Edit question
Solved by:
Corey Goldberg
Solved:
2013-01-17
Last query:
2013-01-17
Last reply:
2013-01-17
Jason Dunckley (coloradojay) said : #1

After writing this and thinking about it more, I have decided to use actions._get_text() directly for now. It still might be a nice enhancement to expose it as an action.

Best Corey Goldberg (coreygoldberg) said : #2

Hi.

WebElements have a `text` property. (I need to add WebElements to the documentation)

so you could do:

elem = get_element(tag="div" css_class="column")
print elem.text

however,
I agree that `get_text()` is a nice enhancement. Feel free to add a bug/issue for it, and I will implement it:
https://bugs.launchpad.net/selenium-simple-test

regards,
-Corey

Corey Goldberg (coreygoldberg) said : #5

get_text() is in trunk.