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

Find.ByXpath does not work on IE

4 Answers 109 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.
Kasjan
Top achievements
Rank 1
Kasjan asked on 24 Feb 2012, 01:56 PM
Hello,

I am working on automated tests for a couple of months now and I was assigned for testing using WebAii a while back.

A couple of weeks ago I found an issue, which I was investigating since then and nothing worked, so I decided to write about it here.

In our project we are using only finding by XPaths only. Other finding methods do not satisfy our needs. The XPaths work on Chrome, FF, Safari and on Internet Explorer, but on the last one sometimes the Find.ByXpath do not work. Here is the example code.

var s = this.ActiveBrowser.Find.ByXPath("//*");

This code should return html and it does on every browser except on some of the Internet Explorer aspx pages.

On IE finding by ID or by tag index works, only the XPaths don't work. Using other XPaths (for example //a[text()='Your Selection']]) also does not work on some sites, it always returns null.

I would like to ask if someone got the same issue as me and my team are experiencing now? Why does some aspx pages don't work with XPaths on IE and some of them do?

If any additional information is needed I will try to provide that informaion.

With regards,

Kasjan

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 25 Feb 2012, 12:02 AM
Hello Kasjan,

I can assure that finding elements by Xpath works in Test Studio using the Standard Xpath Syntax. Take the following HTML sample:

<a href="http://www.telerik.com">Telerik</a>

That HTML Anchor is found and clicked using the following code:

HtmlAnchor a = Find.ByXPath<HtmlAnchor>("//a[text()='Telerik']");
Assert.IsNotNull(a);
a.Click();

See here and here for more examples on finding elements.

If you continue to have difficulty, please provide your exact code against a public page that demonstrates the issue. See here for more details.

Regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Kasjan
Top achievements
Rank 1
answered on 14 Mar 2012, 02:03 PM
Hello again, excuse me for the delay.

Here is the app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="WebAii.Settings" type="ArtOfTest.WebAii.Core.SettingsConfigSectionHandler, ArtOfTest.WebAii, Version=2011.2.1506.0, Culture=neutral, PublicKeyToken=4fd5f65be123776c"/>
    <section name="WebAii.Settings.Web" type="ArtOfTest.WebAii.Core.WebSettingsConfigSectionHandler, ArtOfTest.WebAii, Version=2011.2.1506.0, Culture=neutral, PublicKeyToken=4fd5f65be123776c"/>
  </configSections>
 
  <WebAii.Settings.Web
    aspNetDevServerPort="-1"
    defaultBrowser="InternetExplorer"
    enableScriptLogging="false"
    enableSilverlight="false"
    enableUILessRequestViewing="false"
    killBrowserProcessOnClose="true"
    localWebServer="None"
    recycleBrowser="true"
    silverlightApplicationPath=""
    silverlightConnectTimeout="30000"
    useHttpProxy="false"
    verboseHttpProxy="false"
    webAppPhysicalPath=""
    />
 
  <WebAii.Settings
    annotateExecution="false"
    clientReadyTimeout="30000"
    createLogFile="true"
    enableUILessRequestViewing="false"
    executionDelay="10"
    executionTimeout="30000"
    logAnnotations="false"
    logLocation="C:\WebAiiLog\"
    queryEventLogErrorsOnExit="false"
    simulatedMouseMoveSpeed="0.3"
    unexpectedDialogAction="HandleAndFailTest"
    waitCheckInterval="50"
    xMultiMgr="false"
  />
   
</configuration>

This is the code to execute (truncated, it should find the html anchor on the site)

[TestMethod]
public void TestMethod1()
{
    Settings settings = GetSettings();
    Initialize(settings);
    Manager.LaunchNewBrowser();
    ActiveBrowser.WaitUntilReady();
    ActiveBrowser.Window.Maximize();
    ActiveBrowser.NavigateTo("~");
 
    // Trying to get anything from the site
    var example = ActiveBrowser.Find.ByXPath("//*");
 
}

This is the site (also truncated)

http://dl.dropbox.com/u/13885179/TelerikExample.htm

The code works on FF, on Chrome, on Safari, it does not work only on Internet Explorer (tested on 8 and 9). Using other methods of finding elements is out of the question. If you could provide us with any solution for that problem I would be very grateful.

With regards,

Kasjan
0
Accepted
Anthony
Telerik team
answered on 14 Mar 2012, 11:49 PM
Hello Kasjan,

It seems there's an issue with the page you're testing. The same code executed successfully against a basic public site (Bing.com).

Loading your page in an HTML editor program revealed a few issues:
  • It has two DOCTYPES which is not valid.
  • There's a closing table tag missing near the end (see screen shot).

Even after making these changes, your test did not pass. That means there's some issue elsewhere in your page's HTML preventing the XPath from functioning correctly. We even removed all HTML between the <body> tags and reran the test to prove this. It passed at that point.

The Find.ByXPath("//*") notation is fine for demonstration purposes, but is there an exact XPath expression that isn't working to locate a particular element?

All the best,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Kasjan
Top achievements
Rank 1
answered on 15 Mar 2012, 08:18 AM
Hello Anthony,

I have deleted the second DOCTYPE and resolved some of the tag issues. I noticed, that also the head tag is not being closed at all.

The XPath was successfully found after editing the html file with the resolved issues you have pointed out.

The problem was, that the XPaths were not found at all, now this is working as expected.

Thank you very much for the fast reply, it helped us a lot.

With regards,

Kasjan
Tags
General Discussions
Asked by
Kasjan
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Kasjan
Top achievements
Rank 1
Share this question
or