Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Tried researching but couldn’t succeed.

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading