Skip to content

Instantly share code, notes, and snippets.

private static Object getObject(String elementName) throws Throwable {
Page page = PageManager.getPage(); // Get the current reference to the page I am on.
elementName = elementName.replaceAll("\\s+", "_").toLowerCase(); // Turn our text into all lower case with spaces replaced by underscores to match object names.
Method pageElementName = null;
try {
pageElementName = page.getClass().getMethod(elementName); // Create a Method object to store the PageElement we want to exercise.
} catch(NoSuchMethodException e) {
log.error("Element " + elementName + " is not defined for the page object " + page.getClass().toString() + ". Make sure you have spelled the page object name correctly in your Cucumber step definition and in the page object.");
throw e;
You can’t perform that action at this time.