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

Xpath implementation bug

3 Answers 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 25 Jan 2012, 04:56 PM

Hi

I think there's a bug in Teleriks implementation of xpath, if the following snippet is on the page i get a xml error when running a find.

 

<a class="addthis_button_google_plusone" <%="g:plusone:annotation"%>="none"></a>

I'm doing find by expression like seen below:

private

HtmlFindExpression h1 = new HtmlFindExpression("xpath=//h1");

Assert

.IsNotNull(currentTest.Find.ByExpression(h1), "h1 not found");


The same xpath works fine in if using Selenium.


Below is the error message thrown:
The ':' character, hexadecimal value 0x3A, cannot be included in a name.


Workaround:
HtmlFindExpression("tagname=h1");

But i still hope you fix this bug.

 

3 Answers, 1 is accepted

Sort by
0
Martin
Top achievements
Rank 1
answered on 25 Jan 2012, 05:04 PM
I have a follow up question, I'm used to working with xpath thats why i was using that.

Can you help me how do i make this into a easy understandable find in Telerik?

xpath=//div[contains(@id, 'CurrentPost_headerDiv')]//div[@class='author']

html structure:
<div id="XXX_CurrentPost_headerDiv">
     <h1>
          <div id="XXX_CurrentPost_PostHeader" class="postDetails">
               <div class="details">
                    <div class="author">
0
Accepted
Anthony
Telerik team
answered on 25 Jan 2012, 08:52 PM
Hello Martin,

I'm not certain how the "a" tag from your first post fits into the sample HTML in your second post. Your HtmlFindExpression worked correctly for me, however.

Typically we recommend our users avoid finding elements by Xpath and instead craft their find expressions based on ID, or some other unique attribute. See here and here for more information.

You can located that particular DIV a number of ways:

//By Xpath: fragile if application changes
HtmlDiv e = Find.ByXPath<HtmlDiv>("//div[contains(@id, 'CurrentPost_headerDiv')]//div[@class='author']");
 
//By Expression: useful if no preceding DIV has matching attribute
HtmlDiv d = Find.ByExpression<HtmlDiv>("class=author");
 
//By ID: most reliable. Locate unique parent DIV, then child DIV based on Tag Index
HtmlDiv main = Find.ById<HtmlDiv>("XXX_CurrentPost_headerDiv");
HtmlDiv sub = main.Find.ByTagIndex<HtmlDiv>("div", 2);


All the best,

Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Martin
Top achievements
Rank 1
answered on 26 Jan 2012, 08:36 AM
Issue1: Telerik implementation of Xpath breaking down
I don't have a site were you can actually see this issue, so i will try to remember when the site goes live to post again so you can see the issue and decide if it's a problem with Telerik or site not following standard or what not.


Issue2: How i made the same find without xpath(For anybody interessted)
private HtmlFindExpression postHeader = new HtmlFindExpression("tagname=div", "id=~CurrentPost_PostHeader");
private HtmlFindExpression postAuthor = new HtmlFindExpression("tagname=a", "class=~authorView");

HtmlDiv main = currentTest.Find.ByExpression<HtmlDiv>(postHeader);
HtmlAnchor sub = main.Find.ByExpression<HtmlAnchor>(postAuthor);


It works, but i must admit i still prefer xpath :). But the solution is fine.
Tags
General Discussions
Asked by
Martin
Top achievements
Rank 1
Answers by
Martin
Top achievements
Rank 1
Anthony
Telerik team
Share this question
or