Selenium Grid WebElement gets Null values

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Selenium Grid WebElement gets Null values

m.eminkucuker
Hi,

I want to use selenium grid for any browser and operating system. However, I have been faced to a problem while using RemoteWebDriver. My code (which is very simple, for example clicking a button on a webpage) is running succesfully when I use firefox driver or any other WebDriver types locally, but same code is not working when the driver becomes RemoteWebDriver. It gives error for WebElements because it finds the element but set the values of it (i.e id) to null immediately afterwards. Thus the button can not be clicked or I can not get any attribute of it. Note: I used a lot of versions of grid and selenium (2.46,2.53.0,2.53.1,3.3.1,3.4 etc.) and I also tried on different machines with different OS and browsers.

        System.setProperty("webdriver.gecko.driver", "/home/geckodriver");
        DesiredCapabilities capabilities=DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);

        String Hub = "http://IP:5555/wd/hub"; // IP is my local Ip

        driver = new RemoteWebDriver(new URL(Hub),capabilities);

        driver.manage().window().maximize();

        driver.navigate().to(myURL);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        WebElement myElement = driver.findElement(By.id("buttonProductSearch"));

        myElement.click();

I get java.lang.NullPointerException at the line I used WebElement. It founds the element but then set its values to null somehow.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/682cef7b-d440-4654-b9f4-23090486dc73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Selenium Grid WebElement gets Null values

⇜Krishnan Mahadevan⇝

I don’t think that’s possible.

 

RemoteWebDriver or Selenium for that matter has got nothing to do with resetting a variable back to null (As you claim) because that’s Java and not Selenium.

 

Can you please share a full fledged example that can be executed to recreate this problem ?

 

When I say a full fledged example, I am referring to either a @Test (TestNG/Junit) annotated test method (or) a public static void main() method that can be executed by anyone in this forum to reproduce the problem ?

 

Selenium WebDriver implementation will either throw an exception (if an element cannot be found) or will find an element and return back a proper WebElement representation when driver.findElement() is invoked.

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, May 24, 2017 at 12:58 AM
To: Selenium Users <[hidden email]>
Subject: [selenium-users] Selenium Grid WebElement gets Null values

 

Hi,

 

I want to use selenium grid for any browser and operating system. However, I have been faced to a problem while using RemoteWebDriver. My code (which is very simple, for example clicking a button on a webpage) is running succesfully when I use firefox driver or any other WebDriver types locally, but same code is not working when the driver becomes RemoteWebDriver. It gives error for WebElements because it finds the element but set the values of it (i.e id) to null immediately afterwards. Thus the button can not be clicked or I can not get any attribute of it. Note: I used a lot of versions of grid and selenium (2.46,2.53.0,2.53.1,3.3.1,3.4 etc.) and I also tried on different machines with different OS and browsers.

 

        System.setProperty("webdriver.gecko.driver", "/home/geckodriver");
        DesiredCapabilities capabilities=DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
 
        String Hub = "http://IP:5555/wd/hub"; // IP is my local Ip
 
        driver = new RemoteWebDriver(new URL(Hub),capabilities);
 
        driver.manage().window().maximize();
 
        driver.navigate().to(myURL);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 
        WebElement myElement = driver.findElement(By.id("buttonProductSearch"));
 
        myElement.click();

 

I get java.lang.NullPointerException at the line I used WebElement. It founds the element but then set its values to null somehow.

 

Thanks in advance.

 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/682cef7b-d440-4654-b9f4-23090486dc73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9DF59515-EEBA-486F-B5B9-67FAC65862C6%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Selenium Grid WebElement gets Null values

m.eminkucuker
package test.java.TestNG;

import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class myGrid
{
    WebDriver driver;

    String myURL = "http://www.hepsiburada.com";

    @Test
    public void calculatepercent() throws InterruptedException, MalformedURLException {

        System.setProperty("webdriver.gecko.driver", "/home/geckodriver");
        DesiredCapabilities capabilities=DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);

        String Hub = "http://IP:5555/wd/hub"; // IP is my local Ip

        driver = new RemoteWebDriver(new URL(Hub),capabilities);

        driver.manage().window().maximize();

        driver.navigate().to(myURL);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        WebElement myElement = driver.findElement(By.id("buttonProductSearch"));

        myElement.click();
    }

    @After
    public void closeBrowser()
    {
        driver.quit();
    }
}

This is the whole code. It is very simple, only thing the code is doing that opening a webpage and clicking a button. However, it is stopped and gives error when comes to click() function and while debugging the code I see that WebElements id becomes null, so it throws NullPointerException. (Note: I also run the code for different webpages, the result is same for all.)

Error posted on terminal of the Node:
java.lang.NullPointerException at org.openqa.selenium.remote.server.handler.ClickElement.call(ClickElement.java:30) at org.openqa.selenium.remote.server.handler.ClickElement.call(ClickElement.java:22) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176) 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:748) 14:23:59.667 WARN - Exception: null

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b45024fc-eb30-4f77-9be8-1c806f4b4906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Selenium Grid WebElement gets Null values

m.eminkucuker
In reply to this post by ⇜Krishnan Mahadevan⇝
package test.java.TestNG;

import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class myGrid
{
    WebDriver driver;

    String myURL = "http://www.hepsiburada.com";

    @Test
    public void calculatepercent() throws InterruptedException, MalformedURLException {

        System.setProperty("webdriver.gecko.driver", "/home/geckodriver");
        DesiredCapabilities capabilities=DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);

        String Hub = "http://IP:5555/wd/hub"; // IP is my local IP

        driver = new RemoteWebDriver(new URL(Hub),capabilities);

        driver.manage().window().maximize();

        driver.navigate().to(myURL);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        WebElement myElement = driver.findElement(By.id("buttonProductSearch"));

        myElement.click();
    }

    @After
    public void closeBrowser()
    {
        driver.quit();
    }
}

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/fc07bda7-c96c-4f05-8bc7-1f1854407d14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Selenium Grid WebElement gets Null values

m.eminkucuker
This is my whole code. I only want to open a website and click a button however when the code comes to click() function, it throws NullPointerException. I also tried for different webpages but the result is same for all.

24 Mayıs 2017 Çarşamba 10:33:06 UTC+3 tarihinde [hidden email] yazdı:
package test.java.TestNG;

import org.junit.After;
import <a href="http://org.openqa.selenium.By" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;">org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class myGrid
{
    WebDriver driver;

    String myURL = "<a href="http://www.hepsiburada.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.hepsiburada.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGquZYBtrsP9F4vH-GMbt0HuETOIw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.hepsiburada.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGquZYBtrsP9F4vH-GMbt0HuETOIw&#39;;return true;">http://www.hepsiburada.com";

    @Test
    public void calculatepercent() throws InterruptedException, MalformedURLException {

        System.setProperty("webdriver.gecko.driver", "/home/geckodriver");
        DesiredCapabilities capabilities=DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);

        String Hub = "<a href="http://IP:5555/wd/hub" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2FIP%3A5555%2Fwd%2Fhub\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEFTfTaXSe4tmC8-YiKWwzk_bZSBA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2FIP%3A5555%2Fwd%2Fhub\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEFTfTaXSe4tmC8-YiKWwzk_bZSBA&#39;;return true;">http://IP:5555/wd/hub"; // IP is my local IP

        driver = new RemoteWebDriver(new URL(Hub),capabilities);

        driver.manage().window().maximize();

        driver.navigate().to(myURL);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        WebElement myElement = driver.findElement(By.id("buttonProductSearch"));

        myElement.click();
    }

    @After
    public void closeBrowser()
    {
        driver.quit();
    }
}

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/60106696-6035-4418-b2b4-fc609b195335%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Selenium Grid WebElement gets Null values

⇜Krishnan Mahadevan⇝

I tried executing your code (via IntelliJ) and I am not able to reproduce your issue.

How are you running your test ?

 

 

On an unrelated note, I am seeing that you have mixed both TestNG and Junit annotations (not that it has anything to do with the problem but am just stating this).

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, May 24, 2017 at 1:05 PM
To: Selenium Users <[hidden email]>
Subject: Re: [selenium-users] Selenium Grid WebElement gets Null values

 

This is my whole code. I only want to open a website and click a button however when the code comes to click() function, it throws NullPointerException. I also tried for different webpages but the result is same for all.

24 Mayıs 2017 Çarşamba 10:33:06 UTC+3 tarihinde [hidden email] yazdı:

package test.java.TestNG;

 

import org.junit.After;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.testng.annotations.Test;

 

import java.net.MalformedURLException;

import java.net.URL;

import java.util.concurrent.TimeUnit;

 

public class myGrid

{

    WebDriver driver;

 

    String myURL = "http://www.hepsiburada.com";

 

    @Test

    public void calculatepercent() throws InterruptedException, MalformedURLException {

 

        System.setProperty("webdriver.gecko.driver", "/home/geckodriver");

        DesiredCapabilities capabilities=DesiredCapabilities.firefox();

        capabilities.setCapability("marionette", true);

 

        String Hub = "http://IP:5555/wd/hub"; // IP is my local IP

 

        driver = new RemoteWebDriver(new URL(Hub),capabilities);

 

        driver.manage().window().maximize();

 

        driver.navigate().to(myURL);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

 

        WebElement myElement = driver.findElement(By.id("buttonProductSearch"));

 

        myElement.click();

    }

 

    @After

    public void closeBrowser()

    {

        driver.quit();

    }

}

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/60106696-6035-4418-b2b4-fc609b195335%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/DD3BFD09-CF43-4BE4-8D25-0AE554B38EE1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.