开发者

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

开发者 https://www.devze.com 2023-02-05 17:05 出处:网络
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 i

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 either
  • 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?


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消