How To Identify ATags with StrongTags/EmTags
Posted: Thu Sep 04, 2014 4:41 am
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!
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!