If you take advantage of the PageFactory support in the Selenium project then you may be continuously writing “PageFactory.InitElements(driver, LoginPage)” where ever you are initialising a new page object within your checks, it can get very repetitive depending on your application under test.

So, here is an easier way to do it.

You can initialise the elements within the constructor of the PageObject (PO) by taking advantage of the “this” keyword to refer to the current class instance, like so:

This will stop you repeating yourself in your checks and also remove the need for your checks to know about the driver, which I intend to write about in the coming weeks.

Comments