Home > Mobile >  Selenium-VBA: Get Total No of Options in a DropDown
Selenium-VBA: Get Total No of Options in a DropDown

Time:11-17

I've been trying to get the Total Number of Options in a Dropdown through Selenium VBA and My Code looks like this:

ABC = driver.FindElementByXPath("//*[@id='select_pager']").Size

The HTML Code of the Dropdown looks like this:

<select id="select_pager" name="select_pager" class="dataSelect" onchange="document.ecform.goto.value=this.selectedIndex 1;movePage(0)">
                <option value="1">1</option></select>

Through this, I'm trying to get the No Of Options Available, and the basis on that, I would be taking a set of other actions in the browser.

Tried researching but couldn't succeed.

CodePudding user response:

First cast the element returned by FindElementByXPath to a Select element using AsSelect then get the list of options using Options property and finally, get the number of options using Count property.

ABC = driver.FindElementByXPath("//*[@id='select_pager']").AsSelect.Options.Count
  • Related