Need help to set values of combo boxes in a table via code
Posted: Fri Jul 28, 2017 11:39 pm
Hello, I am using Ranorex 7.1 and this is a vb based project and could use some help with understanding how to work with tables and combo boxes via code and I really don’t understand the mechanics of what is involved (me=vb.net n00b so please keep that in mind).
At the start of the code module I will be at this page looking at a table of hard drives of which the row count is unknown at run time.
Each row contains an ACTION combo box and an APPLY button that the test will need to interact with.
The code needs to iterate each row, find the ACTION combo box for the current row then set it to the 3rd option “CryptoErase”
Once the action option is set it needs to click the APPLY button for that row then continue setting the combo boxes and applying for the remaining rows.
I have only once before created any code that involves iterating table objects (from a different test), it was built with a lot of trial and error from some forum examples. It works for my other test but I don’t fully understand why it work and it is probably not the right/best template to use for this so if there is a better way to start from I am open to suggestion.
Because I don’t know a better way to address the cell directly I am looping through the rows and then keeping my own counter (myCell_IDX) of each cell of the current row. I believe that the ACTION combobox is in cell 7 so I was assuming I could at the very least get its xpath then click on it to verify I have the right object. Of course I don’t need to click it in the final version of the code but rather change its value to the 3rd option (Erase) but baby steps...
The cell xpath at runtime differs from what see in spy. The comment line "'raw getpath example" is what cboAction_xPath = at run time and the lines below it are examples from spy on each of the action combo boxes on the page.
I've also tried:
which gets me:
but the click event gives this error:
In spy the Select object has 3 options:
Option 'number:255'
Option 'number:0'
Option 'number:1'
I assume that 1 = the erase option.
So I could use some help to know if this is a good starting approach and then if so what are my next steps for the current row?
How can I set the combo box value and how do I click APPLY for the current row?
Thanks.
At the start of the code module I will be at this page looking at a table of hard drives of which the row count is unknown at run time.
Each row contains an ACTION combo box and an APPLY button that the test will need to interact with.
The code needs to iterate each row, find the ACTION combo box for the current row then set it to the 3rd option “CryptoErase”
Once the action option is set it needs to click the APPLY button for that row then continue setting the combo boxes and applying for the remaining rows.
I have only once before created any code that involves iterating table objects (from a different test), it was built with a lot of trial and error from some forum examples. It works for my other test but I don’t fully understand why it work and it is probably not the right/best template to use for this so if there is a better way to start from I am open to suggestion.
Code: Select all
Sub Enable_CryptoErase_for_CurrentDrivePage()
Ranorex.Controls.ProgressForm.Hide()
Dim tblPD_Config_SSDs As Ranorex.TBodyTag = repo.Idrac2.tblPD_Config_SSDs
Dim cboAction_xPath As RxPath
repo.Idrac2.Refresh.Click() ' refresh the page
System.Threading.Thread.Sleep(2000)
Dim myRow_IDX As Integer=0
For Each row As TrTag In tblPD_Config_SSDs.Find("./tr")
Dim rowNameCell As TdTag = row.FindSingle("./td[2]") ' extra question what does [2] reference here???
Dim myCell_IDX As Integer =0 ' reset cell idx counter
For Each cell As TdTag In row.Find("./td")
Report.debug("Info","Checking drive row #" & CStr(myRow_IDX+1) )
If myCell_IDX = 7 Then
cboAction_xPath = cell.FromElement(cell).Children(0).GetPath()
'raw getpath example /dom[@domain='100.65.132.1']//div[#'module-div']/div/?/?/div[2]//form[@name='configuration.storage.pdisks']//table/tbody/tr[1]/td[7]/div
'spy examples for each row
' row 1 example /dom[@domain='100.65.132.1']//select[#'304|C|Disk.Bay.20:Enclosure.Internal.0-1:PCIeExtender.Slot.1.operation']
' row 2 exmaple /dom[@domain='100.65.132.1']//select[#'304|C|Disk.Bay.21:Enclosure.Internal.0-1:PCIeExtender.Slot.1.operation']
' row 3 example /dom[@domain='100.65.132.1']//select[#'304|C|Disk.Bay.22:Enclosure.Internal.0-1:PCIeExtender.Slot.1.operation']
Dim myCBO = Host.Local.FindSingle(cboAction_xPath)
myCBO.Click()
End If
myCell_IDX +=1
Next
Next
End Sub
The cell xpath at runtime differs from what see in spy. The comment line "'raw getpath example" is what cboAction_xPath = at run time and the lines below it are examples from spy on each of the action combo boxes on the page.
I've also tried:
Code: Select all
cboAction_xPath = cell.FromElement(cell).Children(0).FindDescendant(Of SelectTag).GetPath()
Code: Select all
/dom[@domain='100.65.132.1']//div[#'module-div']/div/?/?/div[2]//form[@name='configuration.storage.pdisks']/div/div/div/table/tbody/tr[1]/td[7]/?/?/select[@id='304|C|Disk.Bay.20:Enclosure.Internal.0-1:PCIeExtender.Slot.1.operation']
Code: Select all
Public member 'Click' on type 'Element' not found.
Option 'number:255'
Option 'number:0'
Option 'number:1'
I assume that 1 = the erase option.
So I could use some help to know if this is a good starting approach and then if so what are my next steps for the current row?
How can I set the combo box value and how do I click APPLY for the current row?
Thanks.