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

Data drive validation of a hyperlink

5 Answers 105 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 2
Alan asked on 10 Apr 2012, 03:16 PM
I am following the instructions from this thread to validate a hyperlink exists on a web page of search results, however the object being returned is null.  I do not need to click on the link, just verify that there is one link on the page that contains the string from 'WorkItem'.

Am I using the code correctly or is it not designed to find the string among characters (like Substr or Mid)... :|

Any other tips would be great.  Thanks much!
HtmlAnchor a = ActiveBrowser.Find.ByContent<HtmlAnchor>(Data["WorkItem"].ToString());
if (a != null)
{
    Log.WriteLine("Found - " + a);
}
else
{
    Log.WriteLine("Not found");
}

5 Answers, 1 is accepted

Sort by
0
Accepted
Anthony
Telerik team
answered on 10 Apr 2012, 04:24 PM
Hello Alan,

Find.ByContent will search or an exact match based on TextContent, so it won't work if you're trying to make a partial match.

Replace your first line with the following:

HtmlAnchor a = ActiveBrowser.Find.ByExpression<HtmlAnchor>("tagname=a", "textcontent=~" + Data["WorkItem"].ToString());


Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Alan
Top achievements
Rank 2
answered on 10 Apr 2012, 05:04 PM
Thanks for the quick response.  I'm still baffled because I can see the object in the DOM.  For example, I am looking for "DAP-412" on a search results page in SharePoint that is on our intranet.  Here is a line from the DOM of one result that should be found:

<A dir=ltr id=CSR_U_9 title="http://...com/processes/SDLC/SDLC Testing/DAP-412_MANUAL_OS_Download_AA_TS.xls" href="http://...com/processes/SDLC/SDLC Testing/DAP-412_MANUAL_OS_Download_AA_TS.xls">
 

Is there anything further I need to do?  Am I using the correct expressions?  I viewed this User Guide and I'm wondering if I need to delve into Chaining or Hierarchy (or won't that be necessary?).

Thanks again!
Alan
0
Alan
Top achievements
Rank 2
answered on 10 Apr 2012, 05:11 PM
Got it!  I just replaced TextContent with 'title'.  I retested again using 'href' and that worked as well.  Is this a reliable solution?

HtmlAnchor a = ActiveBrowser.Find.ByExpression<HtmlAnchor>("tagname=a", "href=~" + Data["WorkItem"].ToString());
0
Anthony
Telerik team
answered on 10 Apr 2012, 06:00 PM
Hello Alan,

Title and Href are attributes of an element, and will not be used to match based on text content. Text content comes between the HTML tags:

<a href="http://bing.com">Click here for Bing</a>

See here for more information on content validation element types.

Your reworked solution is reliable if the data from your table is unique so it only identifies one element on the page. In other words, if more than one link contains "DAP-412" in the Href attribute, then only the first anchor will be returned (and that may not be what you want). 

Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Alan
Top achievements
Rank 2
answered on 10 Apr 2012, 08:14 PM
Thanks for your help Anthony.  At this stage of the project, I am just concerned if at least one anchor exists that matches.  I added an 'href=?TS.xls' to the conditions to help drill down the results further.  I need to look at the href instead of the TextContent because the TextContent does not have the string that I need to look for in WorkItem.  

Thanks for the info!
Alan
Tags
General Discussions
Asked by
Alan
Top achievements
Rank 2
Answers by
Anthony
Telerik team
Alan
Top achievements
Rank 2
Share this question
or