0

I am using chrome Version 34.0.1847.116 on Mac OSX 64 bit. When I run the testcase using chrome, the testcase fails. The same testcase works in firefox.

public class Test {
    private WebDriver driver;
    String url="http://my.setmore.com/bookingpage/642a419721f241beb5";
    static String st="No Slots Available";
    static String xpath_service=".//*[@id='ed5b41b240aa4095a0']/div/b";
    static String css_currentdate="td.datepickerSelected > a > span";
    private static String xpath_slots="//div[@class='time_sheet']/ul[@class='morning' or 'afternoon' or 'evening']/li/a";

    @Before
    public void setUp(){
        System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver");
        WebDriver driver = new ChromeDriver();              
        driver.manage().window().maximize();
        driver.get(url);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
    @Test
    public void currentdate(){
        driver.findElement(By.xpath(xpath_service)).click(); /*I got an exception at this place*/
        //code
        int count=slots;
        if(count==0) {  
            System.out.println(st);
        } else {
            //code
            currentdate();
        }
    }
    @After
    public void end(){
        driver.quit();
    }
}

This is throwing a java.lang.NullPointer.Exception on the driver.findElement call.

  • Did you ever found a solution, maybe a newer version of chromedriver helped? Could you update this question with newer information? – Niels van Reijmersdal Apr 24 '15 at 14:42
1

From the code it looks that you are not initializing the WebDriver correctly. You declared a private member of WebDriver and never used it.

In your SetUp method do the following change.

public void setUp(){
    System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver");
    driver = new ChromeDriver();              
    driver.manage().window().maximize();
    driver.get(url);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

Hope this helps.

  • Yes, this is likely to fix it. The null pointer exception points to the driver object (or lack of it) being the source of the problem. – Vince Bowdren Apr 24 '15 at 14:50
-1

Try with CSS and check if it works. You could use cssify to do this.

If using CSS works this might be the chromedriver issue with dealing with xpath. Also, try checking with the latest chromedriver.

  • The findElement method doesn't through a null pointer exception if the selector is wrong, so using a css selector won't fix it. This kind of exception is thrown if the driver object doesn't exist. – Vince Bowdren Apr 24 '15 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.