HtmlTableCell Find by Search String

2 posts, 0 answers
  1. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 27 Feb 2012 Link to this post

    I have the following code that searches a table that can be indexed by pages.  What I do not know what is the return value of myTable.Find.ByContent when the search string is not matched.  Also what’s a slick way to do an index search in the pages till the string is found.  I want to mimic what a user would do in index.

    Thanks,

    John

    Dim MySearchString as String
    MySearchString = "Start All over III"
     
     
     
    ' Copy the table into a local variable to make it easier to work with
    Dim myTable As HtmlTable = Pages.JointCommissionResources9.CphTracerPageRadMyOrgTracesTable
    ' Locate the row we want using text content (Enter the String to search by
    Dim row As HtmlTableRow = myTable.Find.ByContent(Of HtmlTableCell)(MySearchString).Parent(Of HtmlTableRow)()
     
    ' Locate the delete icon (which is going to be just an anchor tag) located in the third column of the current row
    'Dim link As HtmlAnchor = row.Cells(5).Find.ByExpression(Of HtmlAnchor)("uniquename=UrgbtnEditResponse")
    'uniquename="UrgbtnNewResponse"
    Dim link As HtmlAnchor = row.Cells(5).Find.ByExpression(Of HtmlAnchor)("uniquename=UrgbtnNewResponse")
    'Dim link As HtmlAnchor = row.Cells(4).Find.ByExpression(Of HtmlAnchor)("value=Print/Preview")
    ' Now that we've found it, click the delete icon
    link.Click()
     
    HtmlTableCell Find By Search String
     
    Dim MySearchString As String
    Dim PageNumber As Integer
     
     
    MySearchString = "this is a new tracer"
    Log.WriteLine("Value: " & MySearchString)
    Log.WriteLine("Pages: " & GetExtractedValue("x2StrongTag").ToString())
     
     
     
    ' Copy the table into a local variable to make it easier to work with
    Dim myTable As HtmlTable = Pages.JointCommissionResources9.CphTracerPageRadMyOrgTracesTable
    Log.WriteLine("Table when Nothing found: " & myTable.ToString)
     
    ' Locate the row we want using text content (Enter the String to search by
    'Dim row As HtmlTableRow = myTable.Find.ByContent(Of HtmlTableCell)("Article B01").Parent(Of HtmlTableRow)()
     
     
     
    Dim row As HtmlTableRow = myTable.Find.ByContent(Of HtmlTableCell)(MySearchString).Parent(Of HtmlTableRow)()
     
    ' Locate the delete icon (which is going to be just an anchor tag) located in the third column of the current row
    'Dim link As HtmlAnchor = row.Cells(5).Find.ByExpression(Of HtmlAnchor)("uniquename=UrgbtnEditResponse")
    'uniquename="UrgbtnNewResponse"
    Dim link As HtmlAnchor = row.Cells(5).Find.ByExpression(Of HtmlAnchor)("uniquename=UrgbtnNewResponse")
    'Dim link As HtmlAnchor = row.Cells(4).Find.ByExpression(Of HtmlAnchor)("value=Print/Preview")
    ' Now that we've found it, click the delete icon
    link.Click()

  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 01 Mar 2012 Link to this post

    Hello John,

    That will return a null reference exception if the search string isn't matched. See our code sample article on HTML Table Searching & Paging for an example on how to accomplish this against a Telerik demo site.

    Regards,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top