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. 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 dou开发者_Go百科btful that this works because of the jquery, even though jquery is loaded on the page); also tried xpath, but that didn't work eitherwaitForText
( 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?
The solution (as provided by the users on the Selenium google group) 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_ContentPlaceHolder1_TheTextBox</td>
<td>regexp:.+</td>
</tr>
>>> Google groups link
Something like this I would do; This will wait for an value in all TextBoxes up to 60 seconds.. When there is a value in all of them, you check them etc and break out of the loop. Otherwise it will fail after 60 seconds.
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try {
if (selenium.getValue("TextBox1") != "" && selenium.getValue("TextBox2") !="" ))
{ Your Logic here..
break;
}
} catch (Exception e) {}
Thread.sleep(1000);
}
精彩评论