Hello,
I have a problem with the script that performs actions on the website.
After selecting the button on the page, a window in the form of a popup opens.
At this point, the script makes pauses (I am not able to display even a msgbox), as I close the window the script goes on.
The problem is that in this pop-up window I have to choose one option from the list and enter data from excel.
How can I solve this?
webscraping script is stopped -> popup Topic is solved
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: webscraping script is stopped -> popup
My guess is that your script is assuming that the page did not load so its waiting. So what I would do is instead of waiting do a regular sleep, and then enter your data
Re: webscraping script is stopped -> popup
This is the functionality, but in the previous step.
The code in which the script crashes looks like this:
Any tips on this?
Code: Select all
while (wb.busy || wb.readystate != 4)
{
sleep, 500
}
Code: Select all
statrek:= oExcel.Application.ActiveSheet.range("I"Row).value
if (statrek= "WYCO")
{
sleep, 500
wb.document.parentWindow.frames[2].document.getElementByID("StatMenuItemOne").click() ; After doing this, the script stops. The window opens, however, the script does not work.
sleep, 5000
MsgBox "Pop-up is open"
MsgBox % wb.document.getElementByID("newState").OuterHTML "msgbox 1"
wb.document.getElementByID("newStat")[0].value := "RR"
wb.document.getElementByID("dateStat1")[0].value := "2018-05-12"
wb.document.getElementByID("dateStat2")[0].value := "2018-05-12"
}
Any tips on this?
- Joe Glines
- Posts: 770
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: webscraping script is stopped -> popup
This sounds like the issue when you click on an "file download" or "file open" dialogue box (not a "pop up" but same concept). This does lock the script & IE. What I typically do is have another script running to deal with it (or I think you can have multiple threads running with a timer).
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: webscraping script is stopped -> popup
If I ran a different script, how can I find the window on which the main script hangs?
- Joe Glines
- Posts: 770
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: webscraping script is stopped -> popup
use the built-in "window spy" tool from AutoHotkey to get class name / title and then use something like WinExist and WinActivate to put the focus on it.
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: webscraping script is stopped -> popup
The window detects me, now another problem.
How can I enter data.
In previous steps I used:
- wb.document.GetElementsByTagName
- wb.document.parentWindow.frames[0].document.getElementByID
- wb.document.parentWindow.frames[1].document.getElementByID
And similar, but now it does not work.
How can I enter data.
In previous steps I used:
- wb.document.GetElementsByTagName
- wb.document.parentWindow.frames[0].document.getElementByID
- wb.document.parentWindow.frames[1].document.getElementByID
And similar, but now it does not work.
- Joe Glines
- Posts: 770
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: webscraping script is stopped -> popup
Sadly there are a ton of reasons why you may not be able to set data. That fact your showing frames are in your path means it can be pretty tricky. Can you first verify you're getting text / data from the page? is the url you're accessing the one you think it is? I would run: MsgBox % wb.LocationURL to make sure you're on the page you think you are...
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: webscraping script is stopped -> popup
Unfortunately, using the "MsgBox% wb.LocationURL" command I will not get the page address.
Because the main script at the opening of this page stops. And the second one I run does not see the object "InternetExplorer.Application".
Unfortunately, I managed to use "send" methods, but it is not as effective as referring to a specific field on the website.
If there was another method that would refer to the object from the first script, maybe it would be different.
Because the main script at the opening of this page stops. And the second one I run does not see the object "InternetExplorer.Application".
Unfortunately, I managed to use "send" methods, but it is not as effective as referring to a specific field on the website.
If there was another method that would refer to the object from the first script, maybe it would be different.
- Joe Glines
- Posts: 770
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: webscraping script is stopped -> popup
Then use a seperate script to grab the script. Btw- you also might need to increase the # of threads for the script. Sorry, I'm very busy now and can't write more. Reach out to me after tomorrow if you are still stuck. [email protected]
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: webscraping script is stopped -> popup
I has same issue, when web page simply waits when it through some pop up that needed to be filled before proceed, so sententiously AHK held until for COM code complete or through some error see my issue https://autohotkey.com/boards/viewtopic.php?f=5&t=20544
I used two script to accomplish that, main script run another script to full that file select file, but that can be done simply in settimer, if you settimer to close that pop up before click see below
I used two script to accomplish that, main script run another script to full that file select file, but that can be done simply in settimer, if you settimer to close that pop up before click see below
Code: Select all
; settimmer here
wb.document.parentWindow.frames[2].document.getElementByID("StatMenuItemOne").click()
sometimmerlabel:
;close that popup the turn off settimer here
retrun
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Re: webscraping script is stopped -> popup Topic is solved
I managed to run a second script that detects the open web page from the first script. However, the address that appears indicates the address of the main page, the one behind the pop-up window.
The exchange of these elements gives nothing
In the end, I found a solution. I do not know yet how it works exactly, but it works.
Code: Select all
IE := WBGet()
WinActivate web page start
MsgBox % IE.LocationURL
return
WBGet(WinTitle="ahk_class IEFrame", Svr#=1) { ; based on ComObjQuery docs
static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
, IID := "{0002DF05-0000-0000-C000-000000000046}" ; IID_IWebBrowserApp
; , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
if (ErrorLevel != "FAIL") {
lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
}
}
}
Code: Select all
, IID := "{0002DF05-0000-0000-C000-000000000046}" ; IID_IWebBrowserApp
; , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
In the end, I found a solution. I do not know yet how it works exactly, but it works.
Code: Select all
pdoc := Get_MODAL_DOCUMENT()
pdoc.getElementByID("user").value:=""
msgbox % pdoc.body.innerHTML
Get_MODAL_DOCUMENT()
{
static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
SendMessage msg, 0, 0, Internet Explorer_Server1, ahk_class Internet Explorer_TridentDlgFrame
if ErrorLevel = FAIL
return ; IE not found.
lResult := ErrorLevel
DllCall("oleacc\ObjectFromLresult", "ptr", lResult
, "ptr", GUID(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}")
, "ptr", 0, "ptr*", pdoc)
; Return the document object, wrapped for usability:
static VT_DISPATCH := 9, F_OWNVALUE := 1
return ComObject(VT_DISPATCH, pdoc, F_OWNVALUE)
}
GUID(ByRef GUID, sGUID) ; Converts a string to a binary GUID and returns its address.
{
VarSetCapacity(GUID, 16, 0)
return DllCall("ole32\CLSIDFromString", "wstr", sGUID, "ptr", &GUID) >= 0 ? &GUID : ""
}