Rashmi Kakade Rashmi Kakade -4 years ago 114
Java Question

Want to click dropdown button using selenium webdriver code

I want to click dropdown button using selenium webdriver code. HTML is as follows:



<div class="btn-group bootstrap-select show-tick ua-bo-select" style="width: 222px;">
<button class="btn dropdown-toggle bs-placeholder btn-default" role="button" data-toggle="dropdown" type="button" data-id="invContactList" title="" data-original-title="Nothing selected">





What will be the accurate code ?

Please check the dropdown button which my application is using

Answer Source

The is no 'a'Tag in this HTML. SO using Select will not work. Instead do this:

driver.findElement(By.xpath(".//button[@data-toggle='dropdown']")).Click();

Then Spy on the dropdown values and give another xpath or ID. It will work.

I think the xpath you have given is wrong.Try the above or below:

     driver.findElement(By.xpath(".//button[@data-id='invContactList']")).Click();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download