1

I'm writing a script to login to an internal html site, click around to the appropriate place, click on a specific row in an HTML table, and click a submit button. I'm pretty much there, except I can't figure out how to click the correct row - or any row for that matter.

Here is the source of the table: HTML Source Here is what I've tried so far after navigating to the page with the table of interest (with no results, but no errors):

 Set mainTable = IE.Document.getElementByID("main").contentwindow.document
 mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).getElementsByTagName("td").Item(3).focus
 mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).getElementsByTagName("td").Item(3).click

The code below tries to change the attributes in the HTML table based on changes that I've observed when manually clicking on a cell, but these changes have no effect on the view of the table (the row should be highlighted when a cell within it is clicked) and still don't allow me to click the submit button, which requires a row to be selected:

 currScenario = mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(1).getElementsByTagName("td").Item(2).realValue 'gets string value for "Current Scenario" field, which I've unsuccessfully tried to use to manually update the "selected" attribute in the table   
 mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).setAttribute  "selected", "ScenarioName=" & currScenario
 mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).setAttribute "class", "Skin_Selection_Color"
 mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).style.setAttribute "highlight", "true"
2
  • You may get better feedback if your html source was in text form and not an image.
    – jc__
    Dec 13, 2016 at 15:07
  • I don't think I'm allowed to share the full source since this an internal company site that could potentially contain sensitive information. The table of interest is selected in the attached image though so you can see its attributes. If you need more details about a particular element I'd be happy to provide that.
    – Jordan C
    Dec 13, 2016 at 15:17

2 Answers 2

0

I am a little fuzzy on what you need, but I think that using css for the row highlight and a onClick for the cell selection..

"the row should be highlighted when a cell within it is clicked"

CSS:

#msg_table tr:hover{background-color:white; }

Javascript:

/* create HTML table in Javascript */
for (var j = 0; j < search_results_length; j++){
    // get zebra striping
    if (j % 2 == 0){
        //even
        zebra = "zebra_0";
    }else{
        //odd
        zebra = "zebra_1";
    }
...
myTable+="<tr class='" + zebra + "' onClick='collapse_section_switch(" + j + ")'>"
/* row click here */

myTable+="<td align='right' onClick='balance_stuff(\"search_results[j].customer_number\")'>" + search_results[j].customer_balance + "</td>"
/* cell click here */
...
}

Does this help at all?

2
  • Sorry, maybe my question wasn't clear. I'm not actually trying to make an HTML table that has the property of rows being highlighted when a cell is clicked. I'm trying to use VBscript to click a cell in an existing HTML table. The problem is that when I send the click command to click a cell, nothing happens. When I click a cell manually, the row is highlighted and I can see changes to the table's attributes in the HTML, but none of that happens when I use .click in VBscript. I also tried to use VBscript to change the table's attributes to their desired post-click values, but that didn't help.
    – Jordan C
    Dec 13, 2016 at 15:35
  • It almost sounds like the DOM assignment of the cell may not be correct... Good luck.
    – jc__
    Dec 13, 2016 at 15:48
0

I still don't understand why the .click() command wouldn't click on the cell, but it turns out the answer was to use .FireEvent("onmouseup").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.