Skip to content
Advertisement

How to check if all the elements present on the page

I am using page object model using page factory selenium using Java

I have page class for example:

JavaScript

I want to check if all the elements defined in the page class are displayed on the webpage. I want to perform this on in all my page classes. Looking for reusable generic method which can be written in BasePage and can be reuse in all the other pages.

Advertisement

Answer

You can so like this below using Java Reflection Create a Abstract Base Class package com.af.steps;

JavaScript

Your Page Class should call it like this , I have Tested this On google and works fine Implement the checkDisplayed and class the base method from Abstract class and pass the Class to it, it will initialize the page suing page factory and check if all webelements are displayed or not

JavaScript

you will an output like below for above example

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement