getproperty in java is returning null

516 views
Skip to first unread message

Sapna Mittal

unread,
Sep 8, 2015, 10:00:28 AM9/8/15
to seleniu...@googlegroups.com
Hi Guys,

I am using Keyword driven Selenium Framework and data is read from excel sheet for steps and keyword and xpaths are read from a text file. In a function, getproperty in java is returning null but if I use xpath directly, it works. Although it was working fine for 3 similar objects correctly.

Pls help.

Thanks & regards,
Sapna Mittal

GURUNADH D

unread,
Sep 8, 2015, 10:48:42 PM9/8/15
to Selenium Users
Check if you have white spaces of that xpath in the text file

Sapna Mittal

unread,
Sep 9, 2015, 6:17:19 AM9/9/15
to seleniu...@googlegroups.com
This is still not working.
txtbx_Basefare=//input[@id='ctl08_ctl00_ctl00_tbBaseAd']

Thanks & regards,
Sapna Mittal

--
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/5a981cd6-ff3b-4080-9b7c-619b39158d08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jegadeesh mani

unread,
Sep 9, 2015, 6:51:49 AM9/9/15
to seleniu...@googlegroups.com
Hi,

Kindly use sop and print the get value, check it now .

Thanks,
Jegadeesh

MWQA

unread,
Sep 9, 2015, 6:51:51 AM9/9/15
to Selenium Users
Don't use xpath - you have the id so use that instead (cleaner, faster)
eg:
txtbx_Basefare = driver.findElement(By.id('ctl08_ctl00_ctl00_tbBaseAd'))

With such limited details though, I'm not sure what other help you are going to get here (posting the relevant source code and your selenium code would help).

Sapna Mittal

unread,
Sep 9, 2015, 7:07:37 AM9/9/15
to seleniu...@googlegroups.com
@Jegadeesh: What is SOP and how to use it?
@MWQA: If I use //input[@id='ctl08_ctl00_ctl00_tbBaseAd'] or (By.id('ctl08_ctl00_ctl00_tbBaseAd')), it is working fine but for a framework, I cannot hard code the value. So I am using the code as:

public DriverScript() throws NoSuchMethodException, SecurityException{
actionKeywords = new ActionKeywords();
method = actionKeywords.getClass().getMethods();
}

    public static void main(String[] args) throws Exception {
    ExcelUtils.setExcelFile(Constants.Path_TestData);
    DOMConfigurator.configure("log4j.xml");
    String Path_OR = Constants.Path_OR;
FileInputStream fs = new FileInputStream(Path_OR);
OR= new Properties(System.getProperties());
OR.load(fs);

DriverScript startEngine = new DriverScript();
startEngine.execute_TestCase();

public static void updatepriceplus(String object, String data){
try{
Log.info("Updating the price in " + object.isEmpty());
Thread.sleep(5000);
driver.findElement(By.xpath(OR.getProperty(object))).click();
Log.info("pass1");
driver.findElement(By.xpath(OR.getProperty(object))).sendKeys(data);
Log.info("pass2");
WebElement textbox = driver.findElement(By.xpath(OR.getProperty(object)));
String existingvaluetext = textbox.getText();
Log.info("Text value " + existingvaluetext);
String existingvaluename = textbox.getAttribute("name");
Log.info("Text value name " + existingvaluename);
String existingvalue = textbox.getAttribute("value");
Log.info(existingvalue);
int inputvalue = Integer.parseInt(data)+ Integer.parseInt(existingvalue);
Log.info("new input value in int is "+ inputvalue);
String finalinputvalue = Integer.toString(inputvalue);
Log.info(finalinputvalue);
driver.findElement(By.xpath(OR.getProperty(object))).sendKeys(finalinputvalue);
Log.info(finalinputvalue + " price is updated in " + object);
DriverScript.bResult = true;
}catch(Exception e){
Log.error("Not able to update data --- " + data + " in " + object+" "+ e.getMessage());
e.printStackTrace();
DriverScript.bResult = false;
}

I debugged and found that OR.getProperty(object) is returning null for one page's all objects.

Pls help.

Thanks & regards,
Sapna Mittal

MWQA

unread,
Sep 9, 2015, 7:41:42 AM9/9/15
to Selenium Users
The code looks overly complex.  I'd create a smaller Find method and return an element, i.e.

public WebElement find(By locator) {
    return driver.findElement(locator);
}

and then small methods to interact with the element..

public void click(By locator){
        find(locator).click();
}

Are you trying to get the value of an attribute, i.e. <a id="test" href="foo">


public String getLinkDestination (By locator) {
    return find(locator).getAttribute("href");
}

Jegadeesh mani

unread,
Sep 9, 2015, 8:39:52 AM9/9/15
to seleniu...@googlegroups.com
Hi,

High lighted the below line, removing exiting line and print the object value. if it print as a null value, then mistake it calling a object of webelement.

SOP(system.out.println).

Thanks,
Jegadeesh
Reply all
Reply to author
Forward
0 new messages