-
Notifications
You must be signed in to change notification settings - Fork 2
Root Causes of net.sf.cglib.core.CodeGenerationException
java.lang.RuntimeException: net.sf.cglib.core.CodeGenerationException: org.openqa.selenium.NoSuchElementException-->Timed out after 10 seconds. Unable to locate the element at com.taf.automation.ui.support.PageObjectV2.initPage(PageObjectV2.java:76) at com.taf.automation.ui.support.PageObjectV2.initPage(PageObjectV2.java:47)
From this stacktrace, it is not obvious why an element is being bound at this point. The reason seems to be that calling any method (even ones that do not having any selenium methods) will trigger the proxy method to be invoked which in turn binds the element for the component. This leads to the NoSuchElementException as the page is not currently displayed at this point. This rolls up to the CodeGenerationException.
In this case, the TabOffTextBox component was calling a method to set variables to default values in the constructor. See the problem code below.
public class TabOffTextBox extends PageComponent { private boolean sendKeysDelay; private int delayInMilliseconds; public TabOffTextBox() { super(); defaultSendKeysDelayConfig(); // This method call generates the exception } public TabOffTextBox(WebElement element) { super(element); defaultSendKeysDelayConfig(); } private void defaultSendKeysDelayConfig() { setSendKeysDelay(false); setSendKeysDelay(100); } }
The solution was to directly set the variables to the default values in the constructor instead. See the fixed code below.
public class TabOffTextBox extends PageComponent { private boolean sendKeysDelay; private int delayInMilliseconds; public TabOffTextBox() { super(); sendKeysDelay = false; // Directly set the variables to the default values delayInMilliseconds = 100; } public TabOffTextBox(WebElement element) { super(element); sendKeysDelay = false; // Directly set the variables to the default values delayInMilliseconds = 100; } }
It is not clear why calling a method triggers the binding but directly setting the variables does not bind the element. I suspect this is working as designed according to Cglib the proxy library being used