how can I test text that is put in to input elements?

139 views
Skip to first unread message

Justin Collum

unread,
Jan 17, 2011, 2:52:48 PM1/17/11
to Selenium Users
I have a web page that pulls some data from my database when someone
types an integer into a text box. The data ends up in some text input
controls. Have to be inputs, because the user is allowed to edit the
data that is pulled from the database. Straightforward. The selenium
that fires the ajax is:

<tr>
<td>fireEvent</td>
<td>ctl00_ContentPlaceHolder1_Wiz1_Control1_TextBox1</td>
<td>blur</td>
</tr>

After the blur event, there are 6 inputs on the page that now have
text in them. I want to wait for the text to be present in the inputs
and assert that they are present. What's an effective way to do this?

I've tried:

- `waitForExpression` with a jquery call (`$('...').val() != ''` but
doubtful that this works because of the
jquery, even though jquery is loaded on the page)
- `waitForText` ( locator, pattern ), which seems like the most
obvious one, but it really won't work, i suspect since the fields are
inputs

Do I need a different approach here because the elements that I'm
querying are `input` controls?

(this is a repost from stackoverflow.com; didn't get any answers there
and posted the question a few days ago)

BillR

unread,
Jan 18, 2011, 3:25:04 PM1/18/11
to Selenium Users
It seems this could be solved in RC/java by

String text = selenium.getText("id_of_input");

or in Selenium 2 by:

WebElement we = driver.findElement(By.id("id_of_input"));
String text = we.getText();

I don't know if Selenese has an equivalent.

Ashok Varma Namburi

unread,
Jan 18, 2011, 9:10:48 AM1/18/11
to Selenium Users
Hi justin,

Try to use 'waitForValue' instead of waitForText.

Thanks,
Ashok

Simon Stewart

unread,
Jan 19, 2011, 8:45:17 AM1/19/11
to seleniu...@googlegroups.com
To get the value of an input element "getValue" is recommended instead
of "getText"

Simon

> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
>
>

Justin Collum

unread,
Jan 19, 2011, 12:37:58 PM1/19/11
to Selenium Users
Seems that wait for value did the trick:

<tr>
<td>waitForValue</td>
<td>ctl00_ContentPlaceHolder1_TheTextBox</td>
<td>regexp:.+</td>
</tr>

I'm pretty confused about why waitForText (in a target control)
wouldn't work but waitForValue would. I burned up a fair amount of
time trying to get this (seemingly simple) test to work. Frustrating.

On Jan 19, 5:45 am, Simon Stewart <simon.m.stew...@gmail.com> wrote:
> To get the value of an input element "getValue" is recommended instead
> of "getText"
>
> Simon
>

Justin Collum

unread,
Jan 18, 2011, 4:11:45 PM1/18/11
to Selenium Users
That makes sense. I tried doing:

waitForExpression : selenium.getText('theTextBox') != ''

But I'm still failing after a timeout.

I've also tried:

<tr>
<td>waitForExpression</td>
<td></td>
<td>document.getElementById('theTextBox').value!=''</td>
</tr>

when I put the "document.getElementById(...)..." js into the firebug
console it evaluates to true. But when I run the Selenium test it just
fails after a timeout.

This looks broken. I can't find any samples of "waitForExpression" on
the net. If you have one please share.

Justin Collum

unread,
Jan 27, 2011, 12:42:40 PM1/27/11
to Selenium Users
The solution is to use waitForValue instead of waitForText. On the one
hand, this could've been a lot easier to figure out. On the other, I
could've known more about the DOM object I was testing.

<tr>
<td>waitForValue</td>
<td>ctl00_..._TheTextBox</td>
<td>regexp:.+</td>
</tr>


Justin Collum

unread,
Jan 27, 2011, 12:43:56 PM1/27/11
to Selenium Users
Thanks, that did it.

On Jan 18, 6:10 am, Ashok Varma Namburi <ashokvarma.namb...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages