brooksd
11 years agoOccasional Contributor
Issues with Firefox EvaluateXPath on First Paragraph Only!
Hello TC forums! First time poster here
Consider the code below. This code is meant to search any wikipedia page and find all of the links in the first paragraph (in this case I hardcoded the URL in and specified the first paragraph directly). The code works by using the findAllChildren method to find all of the elements in the main area with text in then. Near the end of the array is the first paragraph, on which I use an XPath expression to create an array with the links.
function Test()
{
// Obtain the Page object
var url = "http://en.wikipedia.org/wiki/Siyaram_Gangwar";
Browsers.Item(btFirefox).Run(url);
var page = Sys.Browser("*").Page("*").Panel("content").Panel("bodyContent").Panel("mw_content_text");
var tmp = page.FindAllChildren("ObjectType", "TextNode", 1);
// Check the result
if (tmp != null)
{
// Convert the array to the JScript-compatible format
var arr = (new VBArray(tmp)).toArray();
for (var i = 0; i< arr.length; i++)
Log.Message(arr.innerText);
//for this particular page the element we want is the 13th item
var newArray = arr[12].EvaluateXPath("(/a|/a/b)[contains(@href, 'wiki')]");
var newArray2 = (new VBArray(newArray)).toArray();
for (var i = 0; i< newArray2.length; i++){
Log.Message("Link " + i +":" + newArray2.innerText);
}
}
else
{
// If nothing was found, post a message to the log
Log.Error("Nothing was found.");
}
}
The Result: “An unexpected error has occurred”. Now try changing btFirefox to btChrome and it will work fine! Try switching back to FF then using the second paragraph instead of the first (use arr[8] instead of arr[12]) and it will find all of the links in that paragraph! If you throw a breakpoint in there you can see that newArray2 is an array of Objects each one is a link with many members. Now switch it back to the first paragraph and you can see these Objects have no members or information in them at all! The right number of links is there (4) but there is no info in each one.
Is this something I am coding wrong, an issue with Firefox, or an issue with TestComplete10? I am perplexed as to why this works in some cases and not others. Try other paragraphs on other wikis and you will see what I mean.
Any help with this is much appreciated!
Additional info: Windows 7, TestComplete10, Firefox 26.0, Chrome 32
Hi,
To answer all your questions, as far as I can see, the Support Team created an issue in the bug-tracking system. Our R&D team will investigate this behavior. At the moment, it's possible to say that it's specific only to Firefox.