The dropdown list is triggered by an input field. Once the dropdown list is shown, I wanted to select the item based on the index. When I am using PageFactory, (@FindBy) to identify the WebElement, there is always the NullPointerException error.

My question is, is there a (not complicated) way for me to use Select in PageFactory?

  • 1
    i feel this is not a dropdown , but suggested list using ajax call for input box, can you share your code, screenshot of input box and html code?
    – Keshav
    Commented Jan 5, 2017 at 4:57
  • Try sqa.stackexchange.com/questions/21950/… I guess - you need to replace element by driver.pagefactoryWebElement Commented Jan 5, 2017 at 5:38

3 Answers 3


Add a simple wrapper accessor around the WebElement accessor, like this:

WebElement dropdownList;

public Select getSelectOptions() {
  return new Select(dropdownList);

You can add helpful getter and setter methods too, like

public void setOption(int value)

public String getSelectedOption()
    return getSelectOptions().getFirstSelectedOption().getText();

Using the following way we can use Select in Page Factory.


In order to handle items inside a dropdown , Your drop down object should be looks like this. It should be a IList<IWebElement> type

[FindsBy(How = How.ClassName, Using = "<XXXX>")]
 public IList<IWebElement> DropDown { get; set; }

After that using a for each loop go thru each and every item at the DropDown list.


Simply use the Select class of Selenium Webdriver.

Select select = new Select(driver);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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