using SelenideElement: error "Can not set com.codeborne.selenide.SelenideElement..."

977 views
Skip to first unread message

pvi...@gmail.com

unread,
Jun 14, 2016, 3:42:24 PM6/14/16
to selenide
Hi,
Replaced WebElement with SelenideElement in Page Objects as under:

@FindBy(id="userNameId")
private SelenideElement userID;
//private WebElement userID;

Running into following error:
"Can not set com.codeborne.selenide.SelenideElement field pages.Login.userID to com.sun.proxy.$Proxy8"

My structure is as under:

public abstract class Page1

public abstract class Page2 extends Page1

public class Login extends Page2

Thx.
-Vin

Andrei Solntsev

unread,
Jun 16, 2016, 3:37:03 AM6/16/16
to Vinod P, selenide

Hi Vin!
What Selenide version are you using?
I guess it should be fixed in latest version 3.6

--
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pvi...@gmail.com

unread,
Jun 16, 2016, 9:30:04 AM6/16/16
to selenide, pvi...@gmail.com
Selenide 3.6

Andrei Solntsev

unread,
Jun 18, 2016, 5:52:21 PM6/18/16
to Vinod P, selenide
ok, please send
1. the full stack trace of error
2. your code that initializes page object

Andrei Solntsev

2016-06-16 16:30 GMT+03:00 <pvi...@gmail.com>:
Selenide 3.6

pvi...@gmail.com

unread,
Jun 20, 2016, 10:41:08 AM6/20/16
to selenide, pvi...@gmail.com
Now regarding the version, I realized that I had 2 entries in my POM...not sure how/when they got there. One was for 3.6 & another for 'RELEASE'. After I upgraded to Java 1.8.0.92, I removed 3.6.

Replying to your previous post:

Point 2: Page object initialization:
Login page extends Page2
Initialization takes place within the constructor of Page2 as under:

public abstract class Page2 extends Page1
{
protected Page2()
{
super();
PageFactory.initElements(driver, this);
}


Point 1: Stack trace:

java.lang.AssertionError: Can not set com.codeborne.selenide.SelenideElement field pages.Login.userID to com.sun.proxy.$Proxy8

at org.testng.Assert.fail(Assert.java:94)
at supportlibraries.DriverScript.wrapUp(DriverScript.java:617)
at supportlibraries.DriverScript.driveTestExecution(DriverScript.java:120)
at testscripts.RegressionSuite.LoginTests.tc3(LoginTests.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Andrei Solntsev

unread,
Jun 20, 2016, 11:20:17 AM6/20/16
to Vinod P, selenide

Ok, clear. You are using selenium PageFactory that knows nothing about SelenideElements. Don't use PageFactory, use selenide method:

MyPage myPage = page(MyPage.class);

pvi...@gmail.com

unread,
Jun 20, 2016, 11:58:00 AM6/20/16
to selenide, pvi...@gmail.com
Not sure if I understand the implementation of page() method...can you please elaborate some more? Like you want me to replace:
PageFactory.initElements(driver, this);
I commented the line & you indicated that it should be replaced with:
MyPage myPage = page(MyPage.class);

What library will I need to import to get this working?
Just putting the above line in the constructor should take care of the initialization of page objects?
-Vin

Andrei Solntsev

unread,
Jun 20, 2016, 12:20:11 PM6/20/16
to Vinod P, selenide

This is selenide method. No new libraries needed. Don't put this line into constructor, but use it INSTEAD OF constructor. Your page object does not need constructor at all.

pvi...@gmail.com

unread,
Jun 20, 2016, 2:18:54 PM6/20/16
to selenide, pvi...@gmail.com
Ok, tried it. Still failing...

java.lang.AssertionError: Failed to create new instance of class pages.Login <b>Caused by: </b>java.lang.NoSuchMethodException: pages.Login.<init>()

pvi...@gmail.com

unread,
Jun 20, 2016, 2:35:19 PM6/20/16
to selenide, pvi...@gmail.com
It does pass when I remove the extension:
public class Login page extends Page2{}
change to
public class Login {}
and not use the old constructor

I need to use the extension to provide features built into the framework.

So, how do I use Selenide while still extending Mypage class?
-Vin


Andrei Solntsev

unread,
Jun 20, 2016, 5:52:09 PM6/20/16
to Vinod P, selenide

You can extend Page2, but add default public constructor to class Login. Look, error message clearly says that default constructor is missing.

P.S. Are you sure you have upgraded to Selenide 3.6? It should not require constructor.

pvi...@gmail.com

unread,
Jun 21, 2016, 9:08:36 AM6/21/16
to selenide, pvi...@gmail.com
I was using 3.6, then switched to following:
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>RELEASE</version>
</dependency>

Do I need to switch to 3.6?
-Vin

pvi...@gmail.com

unread,
Jun 21, 2016, 9:12:07 AM6/21/16
to selenide, pvi...@gmail.com
Tried using 3.6...same results as with 'RESULT'.
Even though 3.6may not need contstructor, when the Login page extends Page2, it needs the constructor as Page2 has it.
-Vin

pvi...@gmail.com

unread,
Jun 21, 2016, 9:30:40 AM6/21/16
to selenide, pvi...@gmail.com
On debugging, it fails in Selenide.class at line # 302 in method:
public static <PageObjectClass> PageObjectClass page(Class<PageObjectClass> pageObjectClass)

-Vin

pvi...@gmail.com

unread,
Jun 30, 2016, 2:41:37 PM6/30/16
to selenide, pvi...@gmail.com
Andrei,
Checking to see if you could take a look at this...with my limited knowledge, could not go further.
If not resolved, then my option is to NOT use it in place of WebElement & USE it in the methods when Selenide specific options are needed.
Ideally, I would like to use SelenideElement.
Appreciate your help!
-Vin

Andrei Solntsev

unread,
Jun 30, 2016, 6:39:52 PM6/30/16
to Vinod P, selenide
Hi Vin!
I thought I already answered to this question.. Probably in github issue comments...

It seems that your class Login doesn't have public constructor.
Can you write "Login  page = new Login()"?
I bet it would not compile. 

Andrei Solntsev

-Vin

pvi...@gmail.com

unread,
Jul 1, 2016, 9:03:43 AM7/1/16
to selenide, pvi...@gmail.com
I do have a public constructor for Login class.
In another class I composed as you indicated & it compiled fine.
NB: the constructor takes a parameter which is to get a handle onto the data, etc.
-Vin

Andrei Solntsev

unread,
Jul 1, 2016, 11:00:58 AM7/1/16
to Vinod P, selenide

That's the point!
Login class doesn't have public parameterless constructor. That's why Selenide cannot create instance of this class.

pvi...@gmail.com

unread,
Jul 1, 2016, 11:15:14 AM7/1/16
to selenide, pvi...@gmail.com
ok. So, now we know the root cause.
How can we work around this issue?
I need to have the parameter, as its part of our design, and Selenide cannot instantiate it with a parameter.
There has to be some solution/workaround for this...with my minimal knowledge, I may not be able to figure it out...
-Vin

Andrei Solntsev

unread,
Jul 1, 2016, 3:29:56 PM7/1/16
to Vinod P, selenide
Hi Vin!
It's not a problem. You can see that there is 2 "page" methods in class Selenide.
Use the second one:

Login  page = page(new Login(<your parameters here>));


Andrei Solntsev

-Vin

pvi...@gmail.com

unread,
Jul 6, 2016, 9:09:00 AM7/6/16
to selenide, pvi...@gmail.com
Awesomeness!
Ok, after the long weekend...gave it a quick try, failed 1st attempt, realized that PageFactory.initElements was being done twice, commented in my code & it worked...:)
Am loaned out to another project for a short while, so will be back on this soon & building it up...may have questions later...good for now though.
You rock Andrei!!
-Vin

Vin

unread,
Sep 7, 2016, 2:24:59 PM9/7/16
to selenide, pvi...@gmail.com
Hi Andrei,
Revisiting this...after starting back, noticed that since the change was made, the 1st page(Login) that I created works fine using SelenideElement & Page Factory(@FindBy).
The fields are initialized & the methods work.
But same is not true for the next page after Login. "java.lang.NullPointerException" crops up indicating that initialization has not taken place.
Advise if there is anything that needs to be done to get Page Factory to work across all pages.
Thx.
-Vin


Andrei Solntsev

unread,
Sep 7, 2016, 3:27:08 PM9/7/16
to Vin, selenide
Hi Vin!
You don't need to use any page factory at all.
Just use selenide method "page" that creates a page object instance:

Login  page = page(new Login(<your parameters here>));


Andrei Solntsev

--
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+unsubscribe@googlegroups.com.

Vin

unread,
Sep 8, 2016, 10:09:25 AM9/8/16
to selenide, pvi...@gmail.com
I know Andrei, you mentioned it earlier also that 'Page Factory' is not reqd. & generally you don't like it...:)
But then, we need to use it & probably beyond my control to Not use it.
Could not figure out an answer based on your response. I'll describe in detail:
1]public class Page1 extends MasterClass

@FindBy(id="userNameId")
private SelenideElement userID;
public void setUserID(String id) {
userID.setValue(id);
}

2]public class Page2 extends MasterClass
@FindBy(name = "displayName")
private SelenideElement productName;
public void setProductName(String name) {
productName.sendKeys(name);}

In the 1st class, the method (setUserID) works fine with using SelenideElement userID; in the 2nd class, method (setProductName) fails when using SelenideElement productName giving 'java.lang.NullPointerException'.
Not able to understand how 1st one passes while 2nd one fails.
Let me know if I need to provide more input.
Right now working around using private variable in place of SelenideElement & then using that variable within the method:
private String productName = "displayName";
$
(By.name(productName)).sendKeys(name);

Appreciate your help much.
-Vin

Vin

unread,
Sep 9, 2016, 11:04:09 AM9/9/16
to selenide, pvi...@gmail.com
yes Andrei, this worked...man, it takes a while for me to get it...hehehe.
Thx!

Andrei Solntsev

To unsubscribe from this group and stop receiving emails from it, send an email to selenide+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages