0

I want to click the radio button in table and fill value in box in below table

enter image description here

The table will pop up when I click one of this file link.
however my HTMLdocument(HTMLDoc) feel like broken when that happen. My code dont work to click Ok on that table

Here is my code

Set IE2 = CreateObject("InternetExplorer.Application")
apiShowWindow IE2.hwnd, SW_MAXIMIZE

'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE2.Visible = True
IE2.Visible = False
IE2.Visible = True

'Define URL
URL = "https://dgspj-prod.ptcmanaged.com/intellicus/core/SavedReportList.jsp?CATEGORYID="

'Navigate to URL
IE2.navigate URL

' Wait while IE loading...
Do While IE2.readyState = 4: DoEvents: Loop   'Do While
Do Until IE2.readyState = 4: DoEvents: Loop   'Do Until

Set HTMLDoc = IE2.document

    'below not fulfilled in table
    HTMLDoc.getElementById("rdbSeparatorCustom").Click
    HTMLDoc.getElementById("TXT_CSV_COLUMN_SEPARATOR").Value = "~"
    HTMLDoc.getElementById("rdbEnclosureCustom").Click
    HTMLDoc.getElementById("TXT_CSV_COLUMN_ENCLOSURE").Value = ""

    HTMLDoc.querySelector("input[value='Ok']").Click 'not work
    HTMLDocDoc.getElementById("btnSubmit").Click 'not work too

Here is IE Html

<LABEL class=option-label style="MARGIN-LEFT: 42px"><INPUT onclick='fnEnableDisableControls(this,"ENCLOSURE","csv");' id=rdbEnclosureCustom type=radio value=CUSTOM name=CSV_COLUMN_ENCLOSURE_TYPE>Custom</LABEL>
<DIV class=win-btn-wpr><INPUT onclick=fnSetIsDirty();fnSubmit(); id=btnSubmit class="cssButton btn-blue" type=button value=Ok name=btnSubmit> <INPUT onclick=fnHideDiv() id=btnCancel class=cssButton type=button value=Cancel name=btnCancel> </DIV>  

Thank you

Ruzaini Subri
  • 67
  • 2
  • 11

1 Answers1

0

It seems that the VBA code can work well with the provided HTML code. Is there any error when you run the VBA code and in which line the error occures ? Could you give the HTML code which can reproduce the issue? I tested with the following VBA code and it can click the radio button and the submit button:

Sub LOADIE()
Set IE2 = CreateObject("InternetExplorer.Application")

'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE2.Visible = True

'Define URL
URL = "http://test page"

'Navigate to URL
IE2.navigate URL

' Wait while IE loading...
Do While IE2.readyState = 4: DoEvents: Loop   'Do While
Do Until IE2.readyState = 4: DoEvents: Loop   'Do Until

Set HTMLDoc = IE2.document

HTMLDoc.getElementById("rdbSeparatorCustom").Click
HTMLDoc.getElementById("TXT_CSV_COLUMN_SEPARATOR").Value = "test"
HTMLDoc.getElementById("rdbEnclosureCustom").Click
HTMLDoc.getElementById("TXT_CSV_COLUMN_ENCLOSURE").Value = "test"

HTMLDoc.getElementById("btnSubmit").Click

End Sub
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • vba itself dont give any error but function inside html seem cannot work. i put the html code in here [https://www.dropbox.com/s/i0mwmeu06yxe1ux/html%20code%20of%20form.txt?dl=0] – Ruzaini Subri Jan 27 '20 at 13:26
  • I tested with the html code you providing and changed the onclick function in the radio button to `console.log`, it can work well with the above vba code. I think the issue is *function inside html cannot work*, if the function can't be triggered without VBA, then it of course can't be triggered with VBA. Besides, is `HTMLDocDoc` a type error in your VBA code? I think it should be `HTMLDoc`. – Yu Zhou Feb 05 '20 at 07:30
  • Besides, you should pay attention if the pop up table is in an iframe. If it is in an iframe, you can't access the objects directly with `docement.getElementById`. You should reach the iframe first then you can reach the elements. For detailed information, you could refer to [this answer](https://stackoverflow.com/questions/44902558/accessing-object-in-iframe-using-vba/44952913#44952913). – Yu Zhou Feb 05 '20 at 07:39