Question

I'm doing an Internet Explorer Automation using the vb script from a *.vbs file. After detecting a button inside an iframe, I raise the click event of that button which opens a javascript Confirm box and waits for the OK or Cancel click. I'm not able to do a click over the confirm box via script.

I tried so many things but the problem is after the button click, the control goes off from the script and returns back only when I close the Confirm box.

Here is the part of my code:

Set objInputs = internalContent.getElementsByTagName("button")
    for each objInput in objInputs
    strText = objInput.innerHtml
        if (strText = "Submit values") then
            Set wshShell = CreateObject("WScript.Shell")
            objInput.click
            msgbox "testing"
            wshShell.sendkeys "{ENTER}"

My idea is if I could any one of the following scenario, I complete this automation.

1.To delay the whshell.sendkeys wait in the background for sometime and then do the event, while in the mean time the objInput.click gets executed.

Set wshShell = CreateObject("WScript.Shell")
wshShell.sendkeys.sendwait "{ENTER}" , 1000
objInput.click

2.To execute both sendkeys and objInput.click event in the same statement simultaneously (asynchronously).
3.To execute objInput.click with an extra parameter which would return true from the button click event.
4.Use some other control which would execute both the events altogether. A rough example -

msgbox objInput.click & wshShell.sendkeys Chr(24) & wshShell.sendkeys "{ENTER}"

5.To redirect the javascript confirm box into another html so that I can getElement and raise the click event there.

Kindly bare with my non-sense; I learnt vbs just yesterday so I'm not fully aware of the possibilities. Kindly reply if any of the above steps are possible.

Was it helpful?

Solution

I Executed a new script file just before the call to the button click, so that it behaves like a separate thread.
I used WScript.Sleep to wait for a while for the AlertBox to open through the button click, and I fired a sendkeys "{ENTER}" which closed the confirm box as required.

"main_script.vbs" code:

Set wshShell = CreateObject("WScript.Shell")
Set aExec = wshShell.Exec("""C:\Windows\System32\wscript.exe"" ""C:\Users\KiNg\Desktop\sub_script.vbs""")
objInput.click

"sub_script.vbs" code:

Set objShell = CreateObject("WScript.Shell")
WScript.Sleep 1000
objShell.SendKeys "{ENTER}"

Cool ! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top