Selenium Grid WebElement gets Null values

47 views
Skip to first unread message

m.emin...@gmail.com

unread,
May 23, 2017, 11:48:58 PM5/23/17
to Selenium Users
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.

Krishnan Mahadevan

unread,
May 23, 2017, 11:55:54 PM5/23/17
to seleniu...@googlegroups.com

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/

--
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 selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
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.

Message has been deleted

m.emin...@gmail.com

unread,
May 24, 2017, 3:33:06 AM5/24/17
to Selenium Users
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();
    }
}

m.emin...@gmail.com

unread,
May 24, 2017, 3:35:10 AM5/24/17
to Selenium Users
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 m.emin...@gmail.com yazdı:

Krishnan Mahadevan

unread,
May 29, 2017, 10:16:32 AM5/29/17
to seleniu...@googlegroups.com

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/

 


Reply-To: <seleniu...@googlegroups.com>
Date: Wednesday, May 24, 2017 at 1:05 PM
To: Selenium Users <seleniu...@googlegroups.com>

--

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 selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages