Forum Discussion

Raj_Qa's avatar
Raj_Qa
Contributor
13 years ago

Access Web Elements

I am trying to access a web element from a grid, The object Id`s for the Edit link is same for every row, and there are about 50-100 such rows, if I use that object Id to have my test click on the edit link, by default it clicks on the Edit link for the first row. I want it to point to the 10th row but the row number could change, so I have to reference it with one of the values in the same row, I need help in doing that.



I have attached the way the page is coded and the snapshot of the web page itself





I am using firefox 4.0.1, TestComplete 8.6

I am using VBScript

Thanks
  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)
    Hi Raj,



    In your case I recommend using the Page.EvaluateXPath method to get the collection of grid elements. See Finding Web Page Elements by Using XPath Expressions.

    The XPath expression for selecting the edit link in the 10th row will be similar to this one: 

    (//TABLE[@class='dtbl']//TR//TD//A[@class='editRow'])[10]



    Sub Test

        ' Obtain the Page object

        Set page = Sys.Process("firefox").Page("https://scrmqa.autobase.net/Crm/Customer")



        ' Call the function

        obj = page.EvaluateXPath("(//TABLE[@class='dtbl']//TR//TD//A[@class='editRow'])[10]")



        ' Check the result

        If VarType(obj) <> varNull Then

          ' If the element was found, click it

          obj(0).Click ' Note we refer to the array item

        Else

          ' If the element was not found, post a message to the log

          Log.Message "The element was not found"

        End If

    End Sub

  • Hi Artem,

    I checked the source code and the script you wrote seemed perfect, however it returns "The element was not found"


  • Thanks a lot for your help, I changed the source code a little and used the id instead of the class and it worked well.

    Thanks