AHKWebDrive port WebDrive w3c a Autohotkey.

Esta sección es para compartir scripts, librerías y herramientas.

Moderator: Flipeador

devnullsp
Posts: 73
Joined: 21 Nov 2017, 09:00

AHKWebDrive port WebDrive w3c a Autohotkey.

30 Oct 2019, 17:08

Hi,

El WebScraping ha llegado!!!!

https://github.com/devnullsp/ahkWebDrive

He terminado la primera versión del port del api de webdriver el w3c.

NO es un port del Selenium, es el api del webdriver directamente.

Quizás sea un poco "arida" pero es una buena base para montar lo que querais-

Espero que os sea de ayuda.

ESTO.... la documentación está en camino. Aunque en el W3C teneis todas las llamadas.

Devnullsp.

Code: Select all

; get Session (WebDriver is runing @ localhost:9515)
wd := new WDSession("http://localhost:9515")
; navigate to new site
wd.url("https://autohotkey.com")
; click over documentation
wd.element(WDSession.XPath,"//*[@id=""menu-0""]/div/div/div/div[3]/nav/div/ul/li[2]/a").click()
; or use
we :=wd.element(WDSession.XPath,"//*[@id=""menu-0""]/div/div/div/div[3]/nav/div/ul/li[2]/a")
we.click()
; using javascript
we := wd.element(WDSession.XPath,"//*[@id=""menu-0""]/div/div/div/div[3]/nav/div/ul/li[2]/a")
wd.execute("arguments[0].click()",[we])) 
devnullsp
Posts: 73
Joined: 21 Nov 2017, 09:00

Re: AHKWebDrive port WebDrive w3c a Autohotkey.

31 Oct 2019, 15:59

nueva versión.
cambiado de jxon a json :)
Renets
Posts: 36
Joined: 12 Jul 2018, 13:11

Re: AHKWebDrive port WebDrive w3c a Autohotkey.

04 Jul 2020, 12:31

Hello! hey this looks very promising! we need a safe escape to SeleniumBasic (V2), since Selenium is almost at V4, and wee need Autohotkey to keep up with it

I know this is a WIP, but, I tried your code and it gave me this error:
a1.jpg
a1.jpg (44.3 KiB) Viewed 1074 times
https://imgur.com/TDTAH9l

And if I continue the script, it gave this
a2.jpg
a2.jpg (4.21 KiB) Viewed 1074 times
https://imgur.com/whiqb4Q

I am guessing the error is on this line on "test_url.ahk":

Code: Select all

if(wd.rc.isError){
    msgbox % "Error:" wd.rc.value.error " " wd.rc.value.message
    ExitApp
}
Any ideas?


Another thing, I maybe missed it on the doc but how do you set the working browser? and how to target the driver?
like for example like this:

Code: Select all

C:\Program Files\SeleniumBasic\chromedriver.exe
Renets
Posts: 36
Joined: 12 Jul 2018, 13:11

Re: AHKWebDrive port WebDrive w3c a Autohotkey.

04 Jul 2020, 13:57

I am trying my best to workaround on that error without success, if I may, what is the goal with this function:

Code: Select all

__ws(metodo, url, cuerpo:=""){
		static WS_SERVIDOR := ComObjCreate("Msxml2.XMLHTTP")
		local rc:={}
		WS_SERVIDOR.Open(metodo,url, false)
		WS_SERVIDOR.setRequestHeader("Content-Type","application/json; charset=UTF-8")
		WS_SERVIDOR.Send(cuerpo)
		rc.status  := WS_SERVIDOR.Status
		rc.isError := (WS_SERVIDOR.Status < 200 or WS_SERVIDOR.Status > 299)
		rc.raw     := WS_SERVIDOR.ResponseText
		rc.value   := JSON.Parse(rc.raw).value
		rc.sendRaw :=  cuerpo
		return rc
	}

More specifically, are you trying to parse a HTML in plain text as a JSON?

Code: Select all

rc.raw     := WS_SERVIDOR.ResponseText
rc.value   := JSON.Parse(rc.raw).value
I don't quite follow that part, and by many ways I am trying to get a "WS_SERVIDOR.ResponseText" that comes in a JSON but without success as well :(

I also tried using this other ComObjects

Code: Select all

WS_SERVIDOR := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WS_SERVIDOR := ComObjCreate("MSXML2.ServerXMLHTTP")
WS_SERVIDOR := ComObjCreate("MSXML2.XMLHTTP.6.0")
Renets
Posts: 36
Joined: 12 Jul 2018, 13:11

Re: AHKWebDrive port WebDrive w3c a Autohotkey.

04 Jul 2020, 14:08

Yeah, I think the error is in here:

Code: Select all

this.rc := WDSession.__ws("POST", this.prefijo "session",body )
this.sessionId := this.rc.value.sessionid
this.capabilities := this.rc.value.capabilities
I did some troubleshooting and they are empty, so in a function like this one:

Code: Select all

url(url){
        local body := {}
        body.url := url
        this.rc := WDSession.__ws("POST", this.prefijo "session/" this.sessionId "/url", JSON.Stringify(body))
		return this.rc.isError
    }

the "this.sessionId" is empty, and the "session/" messes up the URL, so it now gives the error of "The URL is invalid"

Return to “Scripts y Funciones”

Who is online

Users browsing this forum: No registered users and 4 guests