Share
Go down
venkat
Posts : 3
Join date : 2012-04-10

Unable to find dynamic dropdown items

on Tue Apr 10, 2012 8:50 pm
Hi,

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
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Re: Unable to find dynamic dropdown items

on Wed Apr 11, 2012 12:24 pm
Does this operation -

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

cause page to load? In that case you would need to use - waitForPageToLoad("timeout")

_________________
Thanks
Tarun K
Free Selenium Training
venkat
Posts : 3
Join date : 2012-04-10

Re: Unable to find dynamic dropdown items

on Wed Apr 11, 2012 1:39 pm
Hi tarun k,

Thanks for your reply. i hav added waitforpagetoload command in my script now i got an error "Timed out after 5000 ms". im unable to find solution for this problem.

My sample code:

selenium.Click("//div[@id='ddItem_DropDown']/div/ul/li[" + count + "]");
selenium.WaitForPageToLoad("5000"); //Got error in this line
selenium.Type("name=ddItem", selenium.GetText("//div[@id='ddItem_DropDown']/div/ul/li[" + count + "]"));
string strItemValue = selenium.GetText("//div[@id='ddItem_DropDown']/div/ul/li[" + count + "]");
////ChildDropDown
selenium.Click("//input[@id='ddChild_Input']");
selenium.WaitForPageToLoad("5000");
selenium.Click("//div[@id='ddChild_DropDown']/div/ul/li[1]");
string strChild = selenium.GetText("//div[@id='ddChild_DropDown']/div/ul/li[1]");

Thanks and Regards
Venkat
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Re: Unable to find dynamic dropdown items

on Wed Apr 11, 2012 3:12 pm
can you try with waitForElementPresent method?

_________________
Thanks
Tarun K
Free Selenium Training
avatar
rohit13
Master
Master
Posts : 180
Join date : 2012-03-29
Age : 31
Location : INDIA
http://radical-qa.blogspot.in/

Re: Unable to find dynamic dropdown items

on Wed Apr 11, 2012 3:48 pm
Use below code, this will may help you

Code:
Thread.sleep(7000);

_________________
Radical QA
http://radical-qa.blogspot.in/
venkat
Posts : 3
Join date : 2012-04-10

Re: Unable to find dynamic dropdown items

on Wed Apr 11, 2012 4:47 pm
Hi,

Thanks for all your replies. i hav tried all your solutions but nothing provide expected solution.

Thanks and Regards
Venkat
Rajender
Posts : 1
Join date : 2012-04-11

Re: Unable to find dynamic dropdown items

on Wed Apr 11, 2012 4:49 pm
use Thread.sleep(3000); in between two drop down lists(country and city). It will stops the execution for given time and waits for the city drop down list to load
deshjoshi
Posts : 4
Join date : 2012-04-01

Re: Unable to find dynamic dropdown items

on Mon Apr 16, 2012 3:45 pm
Hi,

After clicking on the dropdown

boolean blnSelect=false;
int intSec=0;
while(blnSelect==false && intSec<120)
{
try
{
if(selenium.isElementPresent("Element ID"));
blnSelect=true;
}
catch(Exception e)
{
intSec++;
Thread.sleep(1000);
}
}

Where 'Element ID' is the element you are waiting for.

Please use this it might help.
After waiting until the element present you can your further comments.
Sponsored content

Re: Unable to find dynamic dropdown items

Back to top
Permissions in this forum:
You cannot reply to topics in this forum