Getting value from text input field

Asked by Jason Dunckley

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()).


<div class="column">
                First Name:
<input type="text" value="Johnny" name="FirstName"/>
<!--many more of these label/input field pairs in this 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's assert_text_contains() which calls _get_text(elem).

Thanks in advance for any suggestions/patches.


Question information

English Edit question
selenium-simple-test Edit question
No assignee Edit question
Solved by:
Corey Goldberg
Last query:
Last reply:
Revision history for this message
Jason Dunckley (coloradojay) said :

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.

Revision history for this message
Best Corey Goldberg (coreygoldberg) said :


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

I agree that `get_text()` is a nice enhancement. Feel free to add a bug/issue for it, and I will implement it:


Revision history for this message
Jason Dunckley (coloradojay) said :
Revision history for this message
Corey Goldberg (coreygoldberg) said :

get_text() is in trunk.