Find.ByXpath workaround for internet explorer

2 posts, 0 answers
  1. bruno
    bruno avatar
    15 posts
    Member since:
    Sep 2010

    Posted 04 Jan 2011 Link to this post

    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
  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 07 Jan 2011 Link to this post

    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
Back to Top