Selenium: Xpath locator can not be used as Option Locator

>In my new job been doing a lot of selenium and i needed to scroll through the list of
options in a select element and click on a particular options.

i have initially used the browser.DoubleClick

browser.DoubleClick(“xpath=//select/option[child::text()=’Option_Label’]”);)

But then this didnt work because selenium doesn’t have the functionality to scroll down the select element in other to make my desired option visible.

Looking through the selenium api, i have used another method, which take in two parameters, the select locator and the option locator.

so i used:

browser.Select(“xpath=//select”, “xpath =//option[child::text()=’Option_Label’]”);

that hasnt work either as the option locator type cannot be xpath. it has to be a label, id, atrribute, name or any other html locator

so i have done

browser.Select(“xpath=//select”, “label=Option_Label”);

which in myown opinion i think is good as it is robust for a selenium test.

Advertisements
This entry was posted in Software Testing and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s