obaid_shirwani
11 years agoContributor
Getting null object in response of xPath
Hi guys,
I am trying the following:
//Set page to be the existing page: Works good.
var page = Sys.Browser("*").Page("*");
//The following is working good and object is getting identified.
var tempObj = page.FindChildByXPath("//input[@id='ddlMonth']");
if(tempObj != null)
{
tempObj.Click();
//tempObj.Text = 'JAN';
}
Sys.Refresh();
//This is the PROBLEM AREA. Here, tempObj gets a null object. The xPath is valid.
tempObj = page.EvaluateXPath("/html/body/div[6]/div/div[5]");
if(tempObj != null)
{
tempObj.Click();
}
What am I doing wrong?
I am trying the following:
//Set page to be the existing page: Works good.
var page = Sys.Browser("*").Page("*");
//The following is working good and object is getting identified.
var tempObj = page.FindChildByXPath("//input[@id='ddlMonth']");
if(tempObj != null)
{
tempObj.Click();
//tempObj.Text = 'JAN';
}
Sys.Refresh();
//This is the PROBLEM AREA. Here, tempObj gets a null object. The xPath is valid.
tempObj = page.EvaluateXPath("/html/body/div[6]/div/div[5]");
if(tempObj != null)
{
tempObj.Click();
}
What am I doing wrong?
- EvaluateXPath returns VBScript-compatible arrays. To use the returned array in JScript, you need to convert it to a native JScript array like this:
var tmp = page.EvaluateXPath(...);
if (tmp != null)
{
var arr = (new VBArray(tmp)).toArray();
...
}
This is mentioned in the EvaluateXPath documentation.