0

I am new to selenium, i got struck for a long time with finding a item in a drop down list that was bind dynamically by selecting item from another dropdown. my sample code is followed by:

selenium.Open(".../Default.aspx");

selenium.WindowMaximize();

selenium.Click("name=ddCountry");

selenium.Click("//div[@id='ddCountry_DropDown']/div/ul/li[1]");

str = selenium.GetText("//div[@id='ddCountry_DropDown']/div/ul/li[1]");

selenium.Type("name=ddCountry", strValue);

selenium.Click("name=ddCity");

selenium.Click("//div[@id='ddCity_DropDown']/div/ul/li[1]");

str = selenium.GetText("//div[@id='ddCity_DropDown']/div/ul/li[1]");

selenium.Click("id=btnRedirect");

selenium.WaitForPageToLoad("30000");

In the above code i was trying to do like after selecting an item in a country dropdown. few items were bind to city dropdown on selectionchange event fires. my problem is " selenium.Click("//div[@id='ddCity_DropDown']/div/ul/li[1]"); " when this code executes i got error like "Element //div[@id='ddCity_DropDown']/div/ul/li[1] not found". please provide a solution for this problem thanks in advance.

regards, Venkat

1 Answers1

0

This is because the city drop down is bond by a country drop down. You need to add some intentional wait after country drop down for city drop down to appear.

You can induce some wait in Java in the first test case after your database code like this:

long end3 = System.currentTimeMillis() + 6000;

    while(System.currentTimeMillis()<end3)
    {
        // Do nothing here Just time pass.  
    } 

This will ensure that Java code waits for 6000 ms

Manpreet Singh
  • 3,643
  • 2
  • 18
  • 14