Page 1 of 1

How To Identify ATags with StrongTags/EmTags

Posted: Thu Sep 04, 2014 4:41 am
by feeblemind099
Hi,

I am looping through search results, say for example Google. And I am searching for Technical Testing.. From the results page, I want to click on the link for "Technical Web Testing 101 - Udemy"..

Thing is, since the ATags have StrongTags/EmTags in them.. the innerText value is somewhat parsed or cut to get rid of the bold texts. say from the above example,

innertext becomes /dom[@domain=link]//ol[#'rso']/div[2]/li[5]//a[@innertext=' Web 101 - Udemy']

how do I make the code data driven that on whenever I tried to search, I will still look on the link as a whole, but just wanted to click the correct innerText value?


Code is something like:

var ds = new DataSet();
var table = ds.Tables.Add("SearchTechnicalTestingInGoogle");
table.Columns.Add("Id", typeof (Int32));
table.Columns.Add("SearchCriteria", typeof (String));
table.Columns.Add("Results", typeof (String));

var idCol = table.Columns["Id"];
idCol.AutoIncrement = true;

var row = table.NewRow();
row.SetField("SearchCriteria", "Technical Testing");
row.SetField("Results", "Technical Web Testing 101 - Udemy");
table.Rows.Add(row);

foreach (DataRow dr in table.Rows)
{
var searchTxtBox = doc.FindSingle<InputTag>("...");
searchTxtbox.TagValue = dr.Field<string>("SearchCriteria");
searchTxtbox.Click();
Keyboard.Press(Keys.Enter);

var searchResults = dr.Field<string>("Results");

if (!TryFindResult(searchResults))
{
throw new Exception("Test Failed. Search Criteria not found.");
}
}



public bool TryFindResult(string searchResults)
{
bool wasLinkFound = false;
string[] words = searchResults.Split(' ');

foreach (string word in words)
{
if notboldwords
{
i want to concat them, say concatText
string concatLink = "...path.. a[@innertext~'" + concatText + "']
var linkToClick = doc.FindSingle<ATag>(concatLink)
linkToClick.MOveTo();
linkToClick.Click();
wasLinkFound = true;
break;
}
}
return wasLinkFound;
}


And since it is data driven, if I cannot find the string up to the last page, it will return something like, I cannot find the link etc.

Thanks!

Re: How To Identify ATags with StrongTags/EmTags

Posted: Mon Sep 08, 2014 3:03 pm
by Support Team
Hello feeblemind099,

I’m afraid that it’s not possible to identify an “a-tag” based on its inner text without knowing its actual “inner text”. Since the Google search generates the “inner text” based on keywords etc. it won’t be possible to search for the link as a whole.

In order to iterate over the links you will need to use the correct “inner text” for object identification. For example: ‘ Web 101 - Udemy’ instead of “Technical Web Testing 101 – Udemy”.

Regards,
Robert