1

enter image description here

so plz help me to resolve this issue.i know how to do dropdown using "select" but in my site it is inside div tag . plz help me to reslove this issue.

HTML Snippet :

 <div class="promptChoiceListBox" style="width: 120px;"> 
     <input id="saw_3005_7_1" class="promptTextField promptTextFieldReadOnly textFieldHelper" type="text" tabindex="0" readonly="" title="" style="width: 101px;"/>  
        <img id="saw_3005_7_1_dropdownIcon" class="promptDropDownButton" tabindex="-1" src="/Myanalytics/res/s_blafp/uicomponents/obips.CommonIconSets/dropdownfilled_e‌​n_choicelistmulti.png" title="" alt="" style="cursor: pointer;" closingdropdownmenu="false"/>
2
  • Can you add the HTML snippet . That would be more helpful – demouser123 Jan 20 '16 at 7:39
  • <div class="promptChoiceListBox" style="width: 120px;"> <input id="saw_3005_7_1" class="promptTextField promptTextFieldReadOnly textFieldHelper" type="text" tabindex="0" readonly="" title="" style="width: 101px;"/> <img id="saw_3005_7_1_dropdownIcon" class="promptDropDownButton" tabindex="-1" src="/Myanalytics/res/s_blafp/uicomponents/obips.CommonIconSets/dropdownfilled_en_choicelistmulti.png" title="" alt="" style="cursor: pointer;" closingdropdownmenu="false"/> – govind Jan 20 '16 at 7:44
1

Try this

First click on the div element. This should open the drop down.

 Webelement ele1 = driver.findElement(By.XPATH("//div[@class='promptChoiceListBox']"));

 ele1.click();

Now we need to implement some kind of wait here so that we have a time gap to allow the elements to load

 //implement some wait here so that element appears
 WebDriverWait wait = new WebDriverWait(driver,30);

 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("saw_3005_7_1")))

Now we need to move to this id element (assuming this is the element in drop down you want to select.

 Actions act = new Actions(driver);

 act.moveToElement(ele1).moveToElement(driver.findElement(By.id("saw_3005_7_1"))).click().build().perform();

Note : This has not been tested.

2
  • dynamic id is generating for the dropdown – govind Jan 21 '16 at 5:14
  • Why didn't you mention this before? – demouser123 Jan 21 '16 at 6:48
1

Try to form the Xpath like

//div[@class='promptChoiceListBox']//input[@id='saw_3005_7_1'] 

Please check the script by finding the element with the above Xpath. Hope it will work because if you take only div tag it will give entire drop down ,but we just need to click on the drop down symbol button in the region of your image added above.

3
  • Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//select[@id='numReturnSelect']/option[@value='15000']"} Command duration or timeout: 200.04 seconds – govind Jan 21 '16 at 5:31
  • i am getting this error – govind Jan 21 '16 at 5:31
  • Hi Govind could you please provide the entire HTML snippet of the <div> tag with all the code expanded. With the code snippet you have provided above drop down looks like a type of text box we are not sure about the entire situation and behavior of it. If you Provide the entire <div> tag code HTML snippet may be we can understand the context well and help you. – Ramesh Uppuluri Jan 21 '16 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.