Error with getBodyText();

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

Error with getBodyText();

Illusion0Reality
        private static WebDriver driver = new FirefoxDriver();
        private static Selenium selenium;
---- the above are declared outside of the function below:

function myfu
        driver.navigate().to("http://www.google.com");
        Thread.sleep(10);
        String al=selenium.getBodyText();

at the last line, I got error - java.lang.NullPointerException

How should I use getBodyText()  
{maybe this is equal to QTP Brower.Page.Object.innerHTML}
Reply | Threaded
Open this post in threaded view
|

Re: Error with getBodyText();

softwaretestingforum
Administrator
illusion0reality wrote
        private static Selenium selenium;
at the last line, I got error - java.lang.NullPointerException
You only declared selenium but did not instantiate it, Hence when you try to use it, you get null pointer exception. b/w try using this to get body text in WebDriver it self -

driver.findElement(By.tagName('body')).getText()
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Error with getBodyText();

Illusion0Reality
Thanks for the reply.
Please let me know how to instantiate selenium.
Because, I have some code which runs solely on selenium object
Though, I won't use it much!
Reply | Threaded
Open this post in threaded view
|

Re: Error with getBodyText();

softwaretestingforum
Administrator
while using only Selenium 1 you instantiate Selenium as -

Selenium selenium = new DefaultSelenium("host IP of Selenium Server", selenium_server_port, "browser", "appURL");

In case of WebDriver you can get WebDriverBackedSelenium as

Selenium selenium = new WebDriverBackedSelenium(driverObject, appURL)

Notice that in case of WebDriverbackedSelenium, you might not be able to use all Selenium 1 API, as it is emulation of Selenium object.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Error with getBodyText();

Illusion0Reality
Thanks, I should have verified the web or IDE.
I thought to say and do this,but you already replied !

So, with Webdriver jars themself, the selenium API does come ?