Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to click on WebElement within a WebTable
#1
Solved: 7 Years, 4 Months, 1 Week ago
I am having some difficulty trying to automate clicking a WebElement that resides within a WebTable.

I have no problems being able to find the row and column with the webtable that contains the value I wish to click on. The problem is the clicking part....

Below is my code for finding the row and column within the WebTable. The problem is with using ChildItem(iRow, iCol, "WebElement", 0). It doesn't want to return a value. It keeps giving me a Object Error.

ANy help would be appreciated!

Thanks!

Code:
row_count=Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").RowCount
col_count=Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ColumnCount(row_count)

For iRow = 1 to row_count
   For iCol = 1 to col_count
     iReturn =  Browser("title:= Supplier T-File Tracking.*").Page("title:=Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItemCount(iRow,iCol,"WebElement")
    
     strReturn =  Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").GetCellData(iRow,iCol)

     Print "This is the cell data: " & strReturn
  
     If strReturn = "READY FOR T-FILE FOCAL" Then
         MsgBox "I found the cell numbers: " & " Row: " &  iRow & " Column: " & iCol
         nCnt = Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItemCount(iRow, iCol, "WebElement")
        Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier
     End If
     If iReturn > 0 Then
        Print "This is row: " & iRow & " and column: " & iCol & " ChildItems = " & iReturn
     End If
   Next
Next

I'm guessing it's because the ChildItemCount value = 0 is why the Object Error appears when I try to do this with the object:

Code:
iChildCnt = Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItemCount(intRow, intColumn, "WebElement")

Set oPartNumberLink = Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItem(intRow, intColumn, "WebElement", 0)

oPartNumberLink.Highlight

I guess I don't understand why ChildItem Count is returning 0 when I know for a fact that is the cell row and column of the value I want.
Reply
#2
Solved: 7 Years, 4 Months, 1 Week ago
fridlek:

I have been playing with dp and webtables recently and I believe the problem is you should be using "Link" instead of "WebElement".

I have come to the conclusion that every cell in a webtable is a webelement. If we need to do something useful such as click on a link, edit a field, check a webcheckbox, then childitem count is greater than 0 and the count for webelement for that cell is > 0.

Try running the code below and you will see what I mean.
Code:
''// http://qaautomationqtp.blogspot.com/2013/07/examples-of-working-with-webtable-in-qtp.html
Public Function func_findObjectinaWebTable(strMicclass,intRow,intCol)
''// This does not work with WebElement, the count is always zero
strmicclass = trim(strMicclass)
'print BrowserName & ": " & tableName
    objChildCnt=Browser("name:="&browserName).Page("title:="&pageTitle).WebTable("name:="&tableName).ChildItemCount(CInt(introw),CInt(intcol),strMicclass)
    print "cnt = " & objChildCnt
    If objChildCnt >0 then
    print "objChildCnt = " & objChildCnt
    print "row " & introw & ", col, " & intcol & ", Micclass " & strMicclass
    End if
End Function

' If any web objects are missing, add them to the array
webObjects_arr = array("Link", "WebButton", "WebCheckBox", "WebEdit","WebElement", "WebTable", "Image", "WebList", "WebRadio", "WebRadioGroup")

' the table I used had 5 rows and 5 columns
For numRow = 1 to 5
    For numCol = 1 to 5
        For i = 0 to ubound(webObjects_arr)
            strMicclass = webObjects_arr(i)
            Call func_findObjectinaWebTable(strMicclass,numRow,numCol)
        Next
    Next    ''// numCol
Next    ''// numRow
I have not played with the last five items in the array.

I am hoping that someone who knows more than I do can explain why cells with an ID of 578912 or FirstName of Paul are not recognized as a webelement when we attempt to perform a count.

hth,

Parke
Reply
#3
Solved: 7 Years, 4 Months, 1 Week ago
Hi Fridlek,

Am not getting what u are asking? Could you please little elaborate the question as whether you are trying to click a link identified as webelement or trying to click on a text?

ensure that some method is used at the end of the statement like any fireevent is used if you are working on the text.

If you are trying to click on the weblink identified as webelement, please use childitem(iRow,iCol,"link",0).click

regards,
Prabhu
Reply
#4
Solved: 7 Years, 4 Months, 1 Week ago
Hi,

I am facing an issue in clicking the Webelement present in Webtable . Below is the line of code

Browser("Browser").Page("Page").Frame("Frame").WebTable("WebTable"). ChildItem(1,5, "WebElement",0)

But I am getting Object Required error. When tried spying the webelement and adding into OR (after browser, page there are multiple Webtables and then last we had WebElement . So we have captured the last Webtable into OR).

Even though the object is added in OR, but still I am getting this error.

Can someone please help me in this regard.

Regards,
Swetha
Reply
#5
Solved: 7 Years, 4 Months, 1 Week ago
can you send the screenshot of that so i can send you the script
Reply
#6
Solved: 7 Years, 4 Months, 1 Week ago
(03-23-2016, 12:35 PM)Swetha_Bayya Wrote: Hi,

I am facing an issue in clicking the Webelement present in Webtable . Below is the line of code

Browser("Browser").Page("Page").Frame("Frame").WebTable("WebTable"). ChildItem(1,5, "WebElement",0)

But I am getting Object Required error. When tried spying the webelement and adding into OR (after browser, page there are multiple Webtables and then last we had WebElement . So we have captured the last Webtable into OR).

Even though the object is added in OR, but still I am getting this error.

Can someone please help me in this regard.

Regards,
Swetha


HI Swetha,

I have similar issue.could you please let me know if you find solution.

my code is clicking on first column
a=Browser("Browser").Page("Page").Frame("Frame").WebTable("WebTable"). ChildItem(1,1, "WebElement",0)
a.click




but if I want to click on 2nd or 3d column ,I am not able to

a=Browser("Browser").Page("Page").Frame("Frame").WebTable("WebTable"). ChildItem(1,2, "WebElement",0)

a.click


Please advise.
Reply
#7
Solved: 7 Years, 4 Months, 1 Week ago
Code:
For iRow = 1 to iRows
   For iCol = 1 to iCols
      sData = Browser("Browser").Page("Page").Frame("Frame").WebTable("WebTable").GetCellData(iRow, iCol)
      If InStr(1, sData, ExpectedValue) Then
         sData.Click
      End If
   Next
Next

try this code for clicking the webelements
Reply
#8
Solved: 7 Years, 4 Months, 1 Week ago
(08-15-2013, 02:06 AM)fridlek Wrote: I am having some difficulty trying to automate clicking a WebElement that resides within a WebTable.

I have no problems being able to find the row and column with the webtable that contains the value I wish to click on. The problem is the clicking part....

Below is my code for finding the row and column within the WebTable. The problem is with using ChildItem(iRow, iCol, "WebElement", 0). It doesn't want to return a value. It keeps giving me a Object Error.

ANy help would be appreciated!

Thanks!

Code:
row_count=Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").RowCount
col_count=Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ColumnCount(row_count)

For iRow = 1 to row_count
  For iCol = 1 to col_count
    iReturn =  Browser("title:= Supplier T-File Tracking.*").Page("title:=Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItemCount(iRow,iCol,"WebElement")
   
    strReturn =  Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").GetCellData(iRow,iCol)

    Print "This is the cell data: " & strReturn
 
    If strReturn = "READY FOR T-FILE FOCAL" Then
        MsgBox "I found the cell numbers: " & " Row: " &  iRow & " Column: " & iCol
        nCnt = Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItemCount(iRow, iCol, "WebElement")
       Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier
    End If
    If iReturn > 0 Then
       Print "This is row: " & iRow & " and column: " & iCol & " ChildItems = " & iReturn
    End If
  Next
Next

I'm guessing it's because the ChildItemCount value = 0 is why the Object Error appears when I try to do this with the object:

Code:
iChildCnt = Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItemCount(intRow, intColumn, "WebElement")

Set oPartNumberLink = Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItem(intRow, intColumn, "WebElement", 0)

oPartNumberLink.Highlight

I guess I don't understand why ChildItem Count is returning 0 when I know for a fact that is the cell row and column of the value I want.

Hi fridlek,

Please try the below way.

Browser("title:= Supplier T-File Tracking.*").Page("title:= Supplier T-File Tracking.*").WebTable("html id:= tfiletable").ChildItemCount(intRow, intColumn, "WebElement").Click

This should definitely work.

Thanks,
Nandana
Reply
#9
Solved: 7 Years, 4 Months, 1 Week ago
(03-23-2016, 12:35 PM)Swetha_Bayya Wrote: Hi,

I am facing an issue in clicking the Webelement present in Webtable . Below is the line of code

Browser("Browser").Page("Page").Frame("Frame").WebTable("WebTable"). ChildItem(1,5, "WebElement",0)

But I am getting Object Required error. When tried spying the webelement and adding into OR (after browser, page there are multiple Webtables and then last we had WebElement . So we have captured the last Webtable into OR).

Even though the object is added in OR, but still I am getting this error.

Can someone please help me in this regard.

Regards,
Swetha

Try to change the index value to 1 or 2 and make a debug run..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gain data from a webtable inside a webtable AndyM 1 1,751 07-12-2018, 08:36 PM
Last Post: Ankur

Forum Jump:


Users browsing this thread: 1 Guest(s)