Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 11 Jun 2022, 04:07

HardyMcFly wrote:
11 Jun 2022, 04:00
Hi
thanks for your work. It is what i needed.
How can I force the next command, before the other command is done?
For example send the next command before site finished loading.
Thanks
Use CDP without CDP script will wait till the page finishes loading, but with CDP need to make your script wait and while can do other stuff but Idk if it's ok to create Create new tab or window while one page is loading or I haven't tried that.
Last edited by Xeo786 on 13 Jun 2022, 02:33, edited 2 times in total.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 11 Jun 2022, 04:09

winkieduck wrote:
11 Jun 2022, 01:12
I am preferring not to use an existing chrome profile and when I log into a website, there will always be this save password notification. I did read the documentation and tried the Session.Alert commands but they don't seem to have any affect on this window. Is there a built in way to close this? I know there are background settings in chrome to disable this password save offering but each time I run my script, it will always open a new chrome window without any profile setting syncs so this is always an issue. any help would be appreciated.

Image
You can use incognito mode
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

ahk7
Posts: 574
Joined: 06 Nov 2013, 16:35

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 13 Jun 2022, 16:20

Perhaps it is just my computer, but perhaps I'm doing something wrong.

I have the test script + test html file below. I set a variable, year:=2022, when I try to use it for an input using .value or .sendkey it doesn't work, but if I add "" infront of it, it does. I see this with chrome and firefox and not only with byName. Just setting "hello" does work.

Code: Select all

#SingleInstance, force
#Include Rufaydium.ahk

Browser:=new Rufaydium()

url:="file:///" StrReplace(A_ScriptDir,"\","/") "/input.htm" ; copied below

Page:=Browser.NewSession()
Page.Navigate(url)

Session:=Browser.getSessionByUrl(url)

Year:=2022

Session.getElementsbyName("input")[0].value:=Year      ; empty
Session.getElementsbyName("input")[1].value:="" Year   ; works
Session.getElementsbyName("input")[2].SendKey(Year)    ; empty
Session.getElementsbyName("input")[3].SendKey("" Year) ; works
Session.getElementsbyName("input")[4].value:="hello"   ; works

MsgBox, Now closing script, browser and webdriver

Browser.QuitAllSessions()
Browser.Driver.exit()
Session:=""
Page:=""
ExitApp
Input.htm

Code: Select all

<html>
<head>
<title>test</title>
</head>
<body>

<form>

<input name='i1' type='text' maxlength='5' size='5' tabindex='1' /><br />
<input name='i2' type='text' maxlength='5' size='5' tabindex='1' /><br />
<input name='i3' type='text' maxlength='5' size='5' tabindex='1' /><br />
<input name='i4' type='text' maxlength='5' size='5' tabindex='1' /><br />
<input name='i5' type='text' maxlength='5' size='5' tabindex='1' /><br />

</form>

</body>
</html>

docterry
Posts: 4
Joined: 13 Jun 2014, 15:51

Re: Rufaydium WebDriver 1.6.0 (no selenium/websocket)

Post by docterry » 13 Jun 2022, 23:43

Xeo786 wrote:
10 Jun 2022, 11:15
docterry wrote:
09 Jun 2022, 01:03
However, when I use session.element[0].click(), it downloads to the default path. Any idea why it would behave like this?
not sure about it will look into that later
If I add in a slight delay in the script, even sleep 100 prior to the click, then the download is saved to the proper folder. Weird!

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.0 (no selenium/websocket)

Post by Xeo786 » 14 Jun 2022, 01:46

docterry wrote:
13 Jun 2022, 23:43
Xeo786 wrote:
10 Jun 2022, 11:15
docterry wrote:
09 Jun 2022, 01:03
However, when I use session.element[0].click(), it downloads to the default path. Any idea why it would behave like this?
not sure about it will look into that later
If I add in a slight delay in the script, even sleep 100 prior to the click, then the download is saved to the proper folder. Weird!
Rufaydium does not have an event handler* for the time being, which may enable AutoHotkey to know if the CDP command has been fully implemented or not?
Webdriver Basics waits for every command to get finished properly but for CDP, it's up to us/code to make the script wait for certain tasks to get finished properly, I am working on the event handler,

TLDR: CDP command takes time to affect (especially commands like changing download folder) and our script does not wait and goes ahead,
Last edited by Xeo786 on 14 Jun 2022, 07:18, edited 1 time in total.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 14 Jun 2022, 02:27

ahk7 wrote:
13 Jun 2022, 16:20
Perhaps it is just my computer, but perhaps I'm doing something wrong.

I have the test script + test html file below. I set a variable, year:=2022, when I try to use it for an input using .value or .sendkey it doesn't work, but if I add "" infront of it, it does. I see this with chrome and firefox and not only with byName. Just setting "hello" does work.
Any value you are sending/setting is being sent to the driver as a string in a JSON object, String should be covered by double quotes (") as Rufaydium Generates AHK object and cJSON.ahk converts it to JSON (text Payload for HTTP request) for Webdriver.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

ahk7
Posts: 574
Joined: 06 Nov 2013, 16:35

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 14 Jun 2022, 12:28

OK I didn't realise, but is that common practice that you have to convert numbers to strings using webdriver?
If I use years:="2022" it does it indeed work as expected (hence the "hello" does too of course).

Shouldn't Rufaydium convert numbers to strings for the .value .sendkey options? That is what I expected and perhaps others too.
If not, it should probably be added to the documentation?
https://github.com/Xeo786/Rufaydium-Webdriver/blob/main/README.md?plain=1#L579 wrote: ;setting value
Element.value := "somevalue"

; Note: when sending a number or variable representing a number, convert it to a string first:
; Element.value := "2022" and not Element.value := 2022
; or
; year := "2022" ; not year := 2022
; Element.value := year
; same goes for .SendKey("2022") and .SendKey(year)
; Alternative prepend variables with a "" to convert it to a string:
; year := 2022
; .value("" year)
; .SendKey("" year)
Edit: or much shorter

All data sent to form elements are required to be strings.

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 15 Jun 2022, 02:04

ahk7 wrote:
14 Jun 2022, 12:28
OK I didn't realise, but is that common practice that you have to convert numbers to strings using webdriver?
If I use years:="2022" it does it indeed work as expected (hence the "hello" does too of course).

Shouldn't Rufaydium convert numbers to strings for the .value .sendkey options? That is what I expected and perhaps others too.
If not, it should probably be added to the documentation?
https://github.com/Xeo786/Rufaydium-Webdriver/blob/main/README.md?plain=1#L579 wrote: ;setting value
Element.value := "somevalue"

; Note: when sending a number or variable representing a number, convert it to a string first:
; Element.value := "2022" and not Element.value := 2022
; or
; year := "2022" ; not year := 2022
; Element.value := year
; same goes for .SendKey("2022") and .SendKey(year)
; Alternative prepend variables with a "" to convert it to a string:
; year := 2022
; .value("" year)
; .SendKey("" year)
Edit: or much shorter

All data sent to form elements are required to be strings.
Yes, it can be fixed using by adding one line, I will try to fix this issue in the next update,
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

elbitjusticiero
Posts: 75
Joined: 06 May 2017, 11:07

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by elbitjusticiero » 15 Jun 2022, 06:42

Hi! I just downloaded Rufaydium and put it in a subfolder in my main (root) AHK scripts folder. It downloaded the operadriver.exe file into the root folder and when trying to run a minimal example, it complained that it couldn't find the driver. I copied the driver into the subfoler where Rufaydium.ahk resides, but I'm still getting the same error.

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 15 Jun 2022, 07:45

elbitjusticiero wrote:
15 Jun 2022, 06:42
Hi! I just downloaded Rufaydium and put it in a subfolder in my main (root) AHK scripts folder. It downloaded the operadriver.exe file into the root folder and when trying to run a minimal example, it complained that it couldn't find the driver. I copied the driver into the subfoler where Rufaydium.ahk resides, but I'm still getting the same error.
Rufaydium downloads the driver itself, read about New Rufaydium()
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Milchmann
Posts: 112
Joined: 05 Nov 2016, 08:50

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Milchmann » 15 Jun 2022, 09:49

I have a request. :clap:
I often query the values .outerHTML , .value and .innerText and then click on these elements.
I can only do this with different queries ( base, cdp and evaluate )

Code: Select all

Chrome := new Rufaydium("chromedriver.exe")
Page := Chrome.getSessionByUrl("https://www.autohotkey.com/boards/")
if !isobject(page)
{
	Page := Chrome.NewSession()
	Page.Navigate("https://www.autohotkey.com/boards/")
}

msgbox %  "`nkeywords innerText from Basic (Autohotkey_H) : " Page.QuerySelectorAll("#page-body > div:nth-child(3) > div > ul.topiclist.forums > li:nth-child(7) > dl > dt > div > a")[0].InnerText  "`n"
. "`nkeywords outerHTML from CDP : `n" Page.cdp.QuerySelector("#keywords").outerHTML "`n`n"
. "`nkeywords outerHTML from Evaluate :  `n" Page.CDP.Evaluate("document.querySelector('#keywords').outerHTML;").value


I can only do this with different queries. Is it possible to optimise this so that I can only query and then click on everything with cdp as an example?
I know I can do this with Evaluate too, but would have to adapt a lot of lines of code with it.

Thanks

elbitjusticiero
Posts: 75
Joined: 06 May 2017, 11:07

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by elbitjusticiero » 15 Jun 2022, 11:32

Xeo786 wrote:
15 Jun 2022, 07:45
elbitjusticiero wrote:
15 Jun 2022, 06:42
Hi! I just downloaded Rufaydium and put it in a subfolder in my main (root) AHK scripts folder. It downloaded the operadriver.exe file into the root folder and when trying to run a minimal example, it complained that it couldn't find the driver. I copied the driver into the subfoler where Rufaydium.ahk resides, but I'm still getting the same error.
Rufaydium downloads the driver itself, read about New Rufaydium()
I know it does, that's why I'm telling you it put the .exe in the root folder, so I had to copy it to the Rufaydium folder, but even so, Rufaydium doesn't find it. ¯\_(ツ)_/¯

elbitjusticiero
Posts: 75
Joined: 06 May 2017, 11:07

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by elbitjusticiero » 15 Jun 2022, 11:38

This is the error I'm getting:

Image

(I said in a reply that didn't get published that I know Rufaydium downloads the driver, but even so, it doesn't seem to find it. It gets downloaded to the main script folder, and even after I manually copy it to the Rufaydium folder, Rufaydium doesn't see it.)

ahk7
Posts: 574
Joined: 06 Nov 2013, 16:35

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 15 Jun 2022, 11:50

@elbitjusticiero perhaps try it like so

Code: Select all

Browser:=new Rufaydium("operadriver.exe")
Page:=Browser.NewSession("c:\path-to\opera.exe")

elbitjusticiero
Posts: 75
Joined: 06 May 2017, 11:07

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by elbitjusticiero » 15 Jun 2022, 13:00

Do you mean that what Rufaydium is not fiding is not the driver, but the browser itself?

ahk7
Posts: 574
Joined: 06 Nov 2013, 16:35

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 15 Jun 2022, 13:20

Yes, it can't find the browser (opera.exe) so if you explicitly call it via Page:=Browser.NewSession("c:\path-to\opera.exe") it hopefully works, did you try it already?

elbitjusticiero
Posts: 75
Joined: 06 May 2017, 11:07

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by elbitjusticiero » 15 Jun 2022, 13:26

Yes, but:

Image

This is the error I'm getting now.

My Opera is up to date so the software is complaining that it only supports a browser that doesn't exist yet.

ahk7
Posts: 574
Joined: 06 Nov 2013, 16:35

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 15 Jun 2022, 13:49

You can manually download drivers here https://github.com/operasoftware/operachromiumdriver/releases just match the versions overwrite the one in your folder and start the script again, should work

elbitjusticiero
Posts: 75
Joined: 06 May 2017, 11:07

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by elbitjusticiero » 15 Jun 2022, 16:47

I'll see if that solves the problem, thank you!

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 16 Jun 2022, 01:33

Milchmann wrote:
15 Jun 2022, 09:49
I can only do this with different queries. Is it possible to optimise this so that I can only query and then click on everything with cdp as an example?
I know I can do this with Evaluate too, but would have to adapt a lot of lines of code with it.

Thanks
Basic WDElement objects store WebDriver element id, and CDP element object stores DOM "nodeid", these are API-level communications that let us do specific tasks,
I compare DOM remote Object ids with WDElement ids and try to match other stuff in order to have a switching ability between CDP to basic at any point/for any element pointer, I haven't found any similarity, unfortunately,

Evaluating javascript is something else that also gives us vast control over the page,
There is evaluate(JS) for CDP, which passes JS,
There are method ExecuteSync(Script,Args*) and ExecuteAsync(Script,Args*), for Basic which executes JS as well.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Post Reply

Return to “Scripts and Functions (v1)”