C # with Selenium Ajax DropdownList issue

I have two drop-down lists, one of which contains a list of countries and one for states / regions that are not populated until one of the countries is selected. Both of these drop-down lists are wrapped in the update panel. When I select USA, the drop-down list of states is populated with 50 states, and I can move on from there.

We use Selenium to run tests of this code, and tests always break when it reaches the status dropdown. Creating a list of states takes too much time, or perhaps it just cannot find the values, because they are not in the original html that is being displayed. I saw some things about javascript "WaitForCondition", but cannot find details on how to use this in selenium documentation. I'm not crazy javascript, but I'm not the best either. Can someone explain to me how you can solve my dilemma, and if this requires knowing how the WaitForCondition field is, can you explain to me how I can make this work?

For the record, I saw this message: (click here to get the postoverflow post semi-task) , but I don’t understand how to relate it to my own situation. Thanks in advance for everything you can give me.

+3
source share
3 answers

So it turns out I found a solution to my problem.

I used the following line in my C # tests and immediately found it in a drop down list:

selenium.WaitForCondition("var ddl = selenium.browserbot.getCurrentWindow().document.getElementById('insert-id-of-dropdownlist-here'); ddl.options[ddl.selectedIndex].text == 'insert-text-value-to-search-for-in-dropdown-here';", "10000");

In the IDE, I used the following parameters:

Command : waitForCondition

: var ddl = selenium.browserbot.getCurrentWindow(). document.getElementById('insert-id-of-dropdownlist-here'); ddl.options [ddl.selectedIndex].text == 'insert-the-text-value-to-search-for-in-dropdown-here';

: 10000

, : http://wiki.openqa.org/display/SEL/waitForCondition

+2

Selenium IDE? , , Selenium RC.

Selenium IDE "waitForText". . ( css, ). , , ( , , ).

, .

,

+4

, , . , option select (, , javascript, -?). option, :

waitForElementPresent | css=option:contains('someState')

:

for (int second = 0;; second++) {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if (selenium.IsElementPresent("css=option:contains('someState')")) break;
                }
                catch (Exception)
                {}
                Thread.Sleep(1000);
            }
+1

Source: https://habr.com/ru/post/1713115/


All Articles