This is a migrated thread and some comments may be shown as answers.

Find.ByXpath workaround for internet explorer

1 Answer 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
bruno
Top achievements
Rank 1
bruno asked on 04 Jan 2011, 08:33 PM
Hello,

I am evaluating the WebAii framework.
I found and issue in xpath related to Internet Explorer.
I am trying to get a specific table. With firefox/firebug the xpath of that table is "/html/body/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[3]/td[2]/table/tbody/tr[3]/td/table/tbody/tr/td/table". In internet explorer that xpath does not works. Returns a null object. I made a search and find out that internet explorer didn't use all the w3c standards for xpath (http://www.w3schools.com/xpath/xpath_syntax.asp).
It says:
"IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]"

On http://www.w3schools.com/xpath/xpath_examples.asp give us a workaround for this problem:
"A Workaround!
To solve the [0] and [1] problem in IE5+, you can set the SelectionLanguage to XPath.
The following example selects the title of the first book node under the bookstore element:
Example
xml.setProperty("SelectionLanguage","XPath");
xml.selectNodes("/bookstore/book[1]/title"); "

In WebAii, there is any workaround? Or should I do it in other way?
The table I want has no name or id. Can't change that. It is defined like this: <table cellspacing="0" cellpadding="2" border="0">.

EDIT: I am using browser.Find.ByXPath<HtmlControl>(xpath).

Best Regards,

Bruno Almeida

1 Answer, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 07 Jan 2011, 06:49 PM
Hi bruno,

One solution we can offer for this problem is to use an IF ELSE block like this:

if (ActiveBrowser.BrowserType == BrowserType.InternetExplorer)
{
    // IE specific actions
}
else
{
    // All other browser type actions
}

Another solution would be to use a chained find expression that will work for all cases. For example:

Find.ByExpression<HtmlTable>("tagname=div", "id=outerdiv", "|", "TagIndex=table:3");

In this example the framework will first find the <div> element that has an id = "outerdiv" then underneath that (that's what the | means) find the 4th <table> element (using 0 based indexing). It will find the 4th without regard to hierarchy/structure. It will be the 4th <table> when the HTML is viewed as one long string.

Find Expressions are pretty powerful once you learn how to use them. They are documented here.
Hope that helps.

Regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
bruno
Top achievements
Rank 1
Answers by
Cody
Telerik team
Share this question
or