Is it possible to get the text that is currently set in a field using SST?

Asked by Lisa Spurrell

I am attempting to use SST to change a text value for an element on my web page while storing the original value. Here is the flow:

1. Get the element I am looking for by name.
2. Store the value that is currently there (not sure how to do this).
3. Write new text to the element (change the value).
4. Continue with test.
....
5. Set value back to original.

myelem = get_element(name = "sample element")
# here's where I would like to store value
#origval = way to do this

write_textfield(myelem, "new text")
# Run the rest of the test

write_textfield(myelem, origval)

Is this possible or is there some workaround I could use to store values that were set prior to my testcase running.
Thanks,
Lisa
write

Question information

Language:
English Edit question
Status:
Solved
For:
selenium-simple-test Edit question
Assignee:
No assignee Edit question
Solved by:
Lisa Spurrell
Solved:
Last query:
Last reply:
Revision history for this message
Corey Goldberg (coreygoldberg) said :
#1

you can access the .text propery of the element.
try this:

myelem = get_element(name = "sample element")
origval = myelem.text
write_textfield(myelem, "new text")
write_textfield(myelem, origval)

-Corey

Revision history for this message
Lisa Spurrell (lisa-spurrell) said :
#2

Hi Corey, thanks for the response.

Unfortunately the myelem.text property is empty. I tried with other elements on my page using myelem.text. I do see the text in the html of the page in the following format:

<input id="sample element" class="editor-field" type="text" value="sample text" name="sample element">

Any idea why the get_element would not set the text property?

Thanks,
Lisa

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

try exploring the returned element with `dir`:

myelem = get_element(name = "sample element")
print dir(myelem)

hopefully there is a useful property you can use.

-Corey

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

> <input id="sample element" class="editor-field" type="text"
> value="sample text" name="sample element">

val = myelem.get_attribute('value')

... should get you "sample text".

-Corey

Revision history for this message
Lisa Spurrell (lisa-spurrell) said :
#5

Thanks Corey! That worked perfectly.

Lisa