Forum Discussion
Hi All,
Thank you for the feedback.This is not working for me,when i used the FindChildByXPath,it is only return the first element,when it should return 5 elements with the below code.
var containerEle;
var ele = "//div[@class='something']/h3";
var elepath= ObjectConverted(ele);
containerEle = page.FindChildByXPath(tablexPath).innerText;
for(i=0; i<=containerEle.length;i++){
Log.MessagecontainerEle [i]);
}
Error seen(Wrong number of arguments or invalid property assignment 12:06:36 Normal Error) with FindAllChildren with the below code:
var containerEle;
var ele = "//div[@class='something']/h3";
var elepath= ObjectConverted(ele);
containerEle = pageFindAllChildren(tablexPath).innerText;
for(i=0; i<=containerEle.length;i++){
Log.MessagecontainerEle [i]);
}
Could you please provide code to make this action funtioned,this is very easy to do with Selenium.Can someone from SmartBear TestComplete help in this situation
Hi,
Unlike Selenium;), TestComplete provides really useful and descriptive documentation with a lot of code samples. So it's definitely worth reading.
Your code is incorrect almost everywhere :)
FindChildByXPath returns first found element, thus it is not possible to iterate through them. EvaluateXPath() returns an array of found elements and it is possible to iterate through the returned array.
FindAllChildren() returns an array and thus it does not contain .innerText property. Also, FindAllChildren() expects not XPath but a different set of parameters.
Final note: while it is possible to search elements in TestComplete via XPath and this may be more convenient for you after Selenium, more effective approach in TestComplete's world is to use Aliases, FindChild() and FindAllChildren() methods. I would recommend you to read about them in the help.
- funmay7 years agoContributor
I am still unable iterate, object expected is triggered as issue when it is about to execute --- if (!strictEqual(arr, null))--- with the below code from TestComplete.Is there any configuartion or settings i need to do that will allow me to iterate elements.
function evalXPath()
{
// Obtain the Page object
var url = "http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onclickEX1.htm";
Browsers.Item(btIExplorer).Run(url);
var page = Sys.Browser("*").Page("*");
// Call the function
var arr = page.EvaluateXPath("//INPUT[contains(@onclick, 'CookieGroup')]");
// Check the result
if (!strictEqual(arr, null))
{
// and click the elements that were found
for (i in arr)
arr[i].Click(); // Note we refer to the array item
}
else
{
// If nothing was found, post a message to the log
Log.Error("Nothing was found.");
}
}- AlexKaras7 years agoChampion Level 3
Hi,
Another point where you may have problems as well:
> page.EvaluateXPath("//INPUT[contains(@onclick, 'CookieGroup')]");
Depending on the page markup, the above may return an element(s) that is/are not wrapped by TestComplete and accessible in the Object Browser but is/are native DOM elements (this is mentioned in the help article where XPath is described). If you happen to get such native DOM element while iterating through the array, then
> arr[i].Click();
will fail because native DOM element does not contain .Click() method and you must call native .click() one instead.
The above is just another reason for the statement that "XPath in TestComplete is the last resort option when nothing else works and must be avoided in favor of Aliases and .FindXXX() methods".
- tristaanogre7 years agoEsteemed Contributor
What language is your TestComplete project set to? There's a note on EvaluateXPath in the help:
Note for JScript, C#Script and C++Script users: The returned array is Variant-compatible. It can be used as is in JavaScript, Python, VBScript and DelphiScript, but if you use JScript, C#Script or C++Script, you have to convert this array to the format supported by the JScript engine. To do this, you can use thetoArray()
method of the variant array
Related Content
Recent Discussions
- 3 days agoMW_Didata