REG: Clarification on Robot framework and Selenium2Library

125 views
Skip to first unread message

Maya.R

unread,
Jan 7, 2014, 2:40:27 AM1/7/14
to robotframe...@googlegroups.com
Hi... I'm using robot framework and selenium2library with Eclipse IDE. I'm in need of certain keywords. So i created keywords using java and invoked in my test script. Now when i run my script , I'm getting a NULL POINTER exception.

REASON:After analysing, My test script already opened browser[using keyword : Open Browser]... and when i execute a java keyword in my test script along with the selenium2library keywords ... the browser is already on run.. and so it is not invoking my java keyword.. so im getting a null pointer exception.

I'm using java to write some keywords because there are keywords not available in selenium2 library to test my application scenario..

Please do share your thoughts..  i know its completely related to selenium2 library but still share your thoughts.

I have knowledge on java and basics of robot framework.... kindly share your thoughts it would be helpful to explore as part of my work..Thank you in advance.  

Markus Bernhardt

unread,
Jan 7, 2014, 3:28:30 AM1/7/14
to maya...@gmail.com, robotframe...@googlegroups.com
You are using the Java version on the Selenium2Library? Then you could do something like:

protected Selenium2Library selenium2Library = Selenium2Library.getLibraryInstance();

public void myKeyword() {
    // access the current browser instance
    WebDriver webDriver = selenium2Library.getBrowserManagement().getCurrentWebDriver();

    // do my special thing with the browser
    ...
}

Hope that helps somehow.
Otherwise we need more information about your code and the thrown exception.

Cheers,
Markus

Markus Bernhardt

unread,
Jan 7, 2014, 3:29:51 AM1/7/14
to Markus Bernhardt, maya...@gmail.com, robotframe...@googlegroups.com
BTW. Which keywords are you missing in Selenium2Library?

Maya.R

unread,
Jan 7, 2014, 3:43:58 AM1/7/14
to robotframe...@googlegroups.com, maya...@gmail.com
Hi im creating a simple code in java as of below

public class xpathmanipulation {

public static WebDriver driver;
public static WebElement webelement;
public  String getxpathdata (String locator)
 
{
 
         webelement = driver.findElement(By.xpath("locator"));
         String text_frmxpath = webelement.getText();
         return text_frmxpath;

    }
 
 
}

Please do guide me how to proceed ..

Maya.R

unread,
Jan 7, 2014, 3:53:05 AM1/7/14
to robotframe...@googlegroups.com, Markus Bernhardt, maya...@gmail.com
Keyword related to Table because the application needs a lot of things related to table..
- get table count. 

Markus Bernhardt

unread,
Jan 7, 2014, 3:53:38 AM1/7/14
to maya...@gmail.com, robotframe...@googlegroups.com
Hi, that cannot work, because you are nowhere initializing the driver varaible. Please try:

public class xpathmanipulation {

protected Selenium2Library selenium2Library = Selenium2Library.getLibraryInstance();


public String getXpathData(String locator) {
WebDriver webDriver = selenium2Library.getBrowserManagement().getCurrentWebDriver();
WebElement webElement = webDriver.findElement(By.xpath(locator));
String text_frmxpath = webelement.getText();
return text_frmxpath;
}
}

This should work or give at least some other error ;-)

BTW. You could simply use the Get Text keyword to do the same.

Maya.R

unread,
Jan 7, 2014, 4:28:25 AM1/7/14
to robotframe...@googlegroups.com, maya...@gmail.com
Hi.. let me try and let you know sooner.thank you.

Maya.R

unread,
Jan 7, 2014, 4:36:28 AM1/7/14
to robotframe...@googlegroups.com, maya...@gmail.com
Actually the work im doing is for web application and i'm getting more doubts for long run. The application is much of little complex and as it is of in table. 
- we used to manipulate using table row number or column number... but to depend on always those table number is there any ways to manipulate the table without using table row or column number.
Let me update on this in a new post..... as of now i'm stuck up with configuration too...
Pls do share your thoughts too... thank you

snehadev...@gmail.com

unread,
May 16, 2017, 7:35:50 AM5/16/17
to robotframework-users, maya...@gmail.com
Hi Markus..I tried the above thing in my code but it fails at compilation level I have a maven project and I am using mac. I have attached my reference library and error console. Please help

import javax.script.ScriptException;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import com.github.markusbernhardt.selenium2library.*;


import com.github.markusbernhardt.selenium2library.utils.WebDriverCache;


public class TransnapJava {

public static void switch_to_canvas() throws ScriptException{

//WebDriver driver = Driver.getDriver();

WebDriver driver = Selenium2Library.getLibraryInstance().getBrowserManagement().getCurrentWebDriver();

driver.findElement(By.xpath("//canvas[@class='upper-canvas ']")).click();

Screen Shot 2017-05-16 at 2.12.51 PM.png
Screen Shot 2017-05-16 at 2.10.52 PM.png
Reply all
Reply to author
Forward
0 new messages