-1

My page has buttons,textboxex and select elements. But when initializing the page objects using PageFactory.initElements(driver,MyPage.class), all elements are initialized except Select element.

I read somewhere that this can be achieved by FieldDecorator or ElementLocatorFactory. But I don't know how to use them.

Need help with this one!!

My Code looks like this

Prasanta Biswas
  • 761
  • 2
  • 14
  • 26

1 Answers1

0

Remove the Select class from variabe declaration and add WebElement instead. It will be initialised by pagefactory.initelements call Then use Select select = new Select(service); in your code for interacting with that element.

One more thing as a coding convention, variable names usually are in camelcase. Class names start with capitals.

Improve some of your xpaths like transactionamounts, comments etc they are suspect to fail if the developer makes even a tiny change in your webpage DOM. As you have the ids use that as the locator instead of xpath. Assuming that the id is unique which the developer should have made sure off.

Grasshopper
  • 8,908
  • 2
  • 17
  • 32
  • Using WebElement instead Select solves it. I have used it. But I want to get the Select object directly rathar than creating select object from the web element. About the code convention, you are right. But the using ids directly in the xpaths gives element not visible exception. That's why I have used them like this. – Prasanta Biswas Aug 11 '16 at 06:55
  • Have a look at this. https://github.com/oraz/selenium. It is implemented by extending FieldDecorator. Should work directly or you might need to modify it. Try moving all your Select operations to a separate class which you can call from your pageobject. Regarding element not visible with ids that is very strange. Does the ids work when you use them directly from the browser. – Grasshopper Aug 11 '16 at 07:13
  • seems to be complex. – Prasanta Biswas Aug 11 '16 at 15:10