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!
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
0
Accepted
Hello Alan,
Greetings,
Anthony
the Telerik team
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
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
<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
Hello Alan,
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
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
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
Thanks for the info!
Alan