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.7.0 (no selenium/websocket)

Post by Xeo786 » 28 Jul 2022, 00:28

usafer wrote:
27 Jul 2022, 13:09
* Manually downloaded and putted cromedriver for chrome 103. I've put it to \chromedriver_win32\file.ahk folder
Yah you can download driver but the best practice is to let Rufaydium download the driver, if browser version mismatches it will let you know and ask to download that driver version to match your browser.

You can also provide the driver's location,

Code: Select all

; untested
Chrome := new Rufaydium("C:\DriverTemp\chromedriver.exe") ; if driver is not there Rufaydium will download driver, if available it will load driver 
providing that location will load the driver but I do not remember testing driver download, I just marked this down and will test it soon,

I am not sure about that error it might be browser error, Please check the following things,
1) Check task manager, No chromedriver.exe is running in the background, kill it before running Rufaydium code.
2) Driver run and occupy a port, Driver will fail to run if that port is occupied, link for default ports.
"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.7.0 (no selenium/websocket)

Post by Xeo786 » 28 Jul 2022, 00:58

murataygun wrote:
27 Jul 2022, 13:23
Can i wait user to click a specified button and then continue?
why not use automation? just write a code to automatically click the button with the specific condition.

Make a code wait is very simple, Just put some conditions to make it sleep while something is not visible/vanished/done/undone Etc.

but specifying some buttons while the code is waiting, it would be a bit complicated

You can use settimer, so the script will execute (not so simple) code while waiting,
but the question is how you specify the button.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

usafer
Posts: 6
Joined: 30 Nov 2021, 09:09

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by usafer » 28 Jul 2022, 04:04

Xeo786 wrote:
28 Jul 2022, 00:28
usafer wrote:
27 Jul 2022, 13:09
* Manually downloaded and putted cromedriver for chrome 103. I've put it to \chromedriver_win32\file.ahk folder
Yah you can download driver but the best practice is to let Rufaydium download the driver, if browser version mismatches it will let you know and ask to download that driver version to match your browser.
well... you're right, but I've meant what I did trying to fix it.
You can also provide the driver's location,

Code: Select all

; untested
Chrome := new Rufaydium("C:\DriverTemp\chromedriver.exe") ; if driver is not there Rufaydium will download driver, if available it will load driver 
providing that location will load the driver but I do not remember testing driver download, I just marked this down and will test it soon,
it's working fine and downloads the driver as wished, but doesn't help to use Rufaydium
I am not sure about that error it might be browser error, Please check the following things,
1) Check task manager, No chromedriver.exe is running in the background, kill it before running Rufaydium code.
2) Driver run and occupy a port, Driver will fail to run if that port is occupied, link for default ports.
that's checked.
The 64-bit isn't a problem?

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 28 Jul 2022, 07:56

usafer wrote:
28 Jul 2022, 04:04
The 64-bit isn't a problem?
there is only 32bit Chromedriver, which work for both 32bit/64bit chrome browsers
usafer wrote:
28 Jul 2022, 04:04
it's working fine and downloads the driver as wished, but doesn't help to use Rufaydium
So you are still facing that message when you create a new session? that says

Code: Select all

"unknown error: DevToolsActivePort file doesn't exist Stacktrace:"
I have searched about it, and found this, so its chrome+user issue

try use setUserProfile() method, it will load chrome with default user profile

Code: Select all

#include Rufaydium.ahk 
Chrome := new Rufaydium() 
Chrome.capabilities.setUserProfile() ; it will load chrome with default user 

; default userDataDir location
; userDataDir := "C:/Users/" A_UserName "/AppData/Local/Google/Chrome/User Data" ; you can change location here 
; Chrome.capabilities.setUserProfile("Default",userDataDir) ; in case userDataDir  is something else in your windows 

Page := Chrome.NewSession()

; Chromeapp := A_ProgramFiles "\Google\Chrome\Application\chrome.exe"
; Page := Chrome.NewSession(Chromeapp) ; in case executable location is changed for you

Page.url := "https://www.autohotkey.com/boards" ; this navigate just line page.navigate(url)
Msgbox, % Page.Title "`n" Page.URL 
return
I disabled a few lines which are easy to set references for chrome options
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

usafer
Posts: 6
Joined: 30 Nov 2021, 09:09

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by usafer » 29 Jul 2022, 02:43

@Xeo786, thanks.
It looks like a step in correct direction.

Now I see new Chrome' window but default URL (so script doesn't opens link).

And look what I see: (Screenshot_26.png attachement)

In this case code what used is:

Code: Select all

#include Rufaydium.ahk 
Chrome := new Rufaydium() 
Chrome.capabilities.setUserProfile() ; it will load chrome with default user 

; default userDataDir location
userDataDir := "D:\Users\" A_UserName "/AppData/Local/Google/Chrome/User Data" ; you can change location here 
Chrome.capabilities.setUserProfile("Default",userDataDir) ; in case userDataDir  is something else in your windows 

Page := Chrome.NewSession()

; Chromeapp := A_ProgramFiles "\Google\Chrome\Application\chrome.exe"
; Page := Chrome.NewSession(Chromeapp) ; in case executable location is changed for you

Page.url := "https://www.autohotkey.com/boards" ; this navigate just line page.navigate(url)
Msgbox, % Page.Title "`n" Page.URL 
return
If I commenting the

Code: Select all

Chrome.capabilities.setUserProfile("Default",userDataDir) ; in case userDataDir  is something else in your windows 
I see all as was before.

If I create new profile and choose it like:

Code: Select all

Chrome.capabilities.setUserProfile("Profile 2",userDataDir)
I see same (busy profile message)

OK, then I thought to use maybe portable chrome?
I've choosed portableapps with chrome beta and changed the code:

Code: Select all

#include Rufaydium.ahk 
Chrome := new Rufaydium() 
userDataDir := "C:\PortableApps\GoogleChromePortableBeta\Data\profile" ; you can change location here 
Chrome.capabilities.setUserProfile("Profile 2",userDataDir) ; in case userDataDir  is something else in your windows 

Page := Chrome.NewSession()

Chromeapp := "C:\PortableApps\GoogleChromePortableBeta\App\Chrome-bin\chrome.exe"
Page := Chrome.NewSession(Chromeapp) ; in case executable location is changed for you

Page.url := "https://www.autohotkey.com/boards" ; this navigate just line page.navigate(url)
Msgbox, % Page.Title "`n" Page.URL 
return
...and that helps!

BUT! I still get that error what I've show you before (screenshot25.png attachement). Why?

And maybe an idea:
I've test it using my laptop and all working fine.
Not sure, but... Is any win11 users here? Maybe win11 doesn't allows to operate with Chrome profile folders?
Attachments
Screenshot_25.png
Screenshot_25.png (24.51 KiB) Viewed 3737 times
Screenshot_26.png
Screenshot_26.png (14.91 KiB) Viewed 3737 times

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 29 Jul 2022, 03:30

@usafer
It feels like file access privilege issue for ChromeDriver.exe, actually Autohotkey runs chromedriver, Win11 takes it as Process(chromedriver) not being run by the user probably.

try create a director in other than 'C:'. May be 'D:' or 'E:' driver, and pass that location as "userDataDir". check if driver can access that location
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by murataygun » 30 Jul 2022, 05:20

Xeo786 wrote:
28 Jul 2022, 00:58
murataygun wrote:
27 Jul 2022, 13:23
Can i wait user to click a specified button and then continue?
why not use automation? just write a code to automatically click the button with the specific condition.

Make a code wait is very simple, Just put some conditions to make it sleep while something is not visible/vanished/done/undone Etc.

but specifying some buttons while the code is waiting, it would be a bit complicated

You can use settimer, so the script will execute (not so simple) code while waiting,
but the question is how you specify the button.
Thank you,

User has to input captcha text to the input box than click the ok button. I cant automate captchas. Bu now i think.. Captcha text is fixed size. 6 letters. Maybe i can click the button when input box has 6 letters. i'll think about it.

noorudin
Posts: 3
Joined: 24 Dec 2020, 04:01

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by noorudin » 04 Aug 2022, 05:09

trying to access the [clear data](as 0 and 4 indicated) button inside the [clear browsing data] in the settings page of chrome, steps to indication 2 were fine, but failed at the indication 3.(as below screenshot)
settings.png
settings of chrome
settings.png (170.38 KiB) Viewed 3381 times
the code went wrong to the indication 3. as showing below

Code: Select all

#SingleInstance, force
#Include %A_ScriptDir%\Rufaydium.ahk
{	; ** ChromeDriver **
	Browser:=new Rufaydium()
	Page:=Browser.NewSession()
}
	Page.Navigate("chrome://settings/privacy")
	If IsObject(Page){
		elem:=Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow().querySelector("#basicPage").querySelector("settings-section:nth-child(9)").querySelector("settings-privacy-page").shadow().querySelector("settings-clear-browsing-data-dialog")
		MsgBox,,, % json.dump(elem)
	}

Page.Quit()
Page.Close()

Browser.QuitAllSessions()
Browser.Exit()
return
the wrong message showing below:
step_3.png
step_3.png (22.26 KiB) Viewed 3381 times
if I commented the last querySelector, like this:

Code: Select all

elem:=Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow().querySelector("#basicPage").querySelector("settings-section:nth-child(9)").querySelector("settings-privacy-page").shadow()
;.querySelector("settings-clear-browsing-data-dialog")
I can access the shadow-root, as showing below:
step_2.png
step_2.png (7.53 KiB) Viewed 3381 times
if I commented the last shadow(), like this:

Code: Select all

elem:=Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow().querySelector("#basicPage").querySelector("settings-section:nth-child(9)").querySelector("settings-privacy-page")
;.shadow()
I cad access the "settings-privacy-page" element as well.
I had try it many times but always failed at indication 3.
could someone know what's wrong with me or else? :crazy: :cry: :headwall:

MoUse_G
Posts: 10
Joined: 07 Oct 2021, 00:52

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by MoUse_G » 04 Aug 2022, 08:27

I can't login to gmail, when using Rufaydium with chromedriver and geckodriver. Has anyone had the same experience with this?
Attachments
image.png
image.png (22.08 KiB) Viewed 3367 times

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 05 Aug 2022, 00:56

MoUse_G wrote:
04 Aug 2022, 08:27
I can't login to gmail, when using Rufaydium with chromedriver and geckodriver. Has anyone had the same experience with this?
You can load a chrome profile that may have already logged in Gmail, .setUserProfile("Profile 1")
"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.7.0 (no selenium/websocket)

Post by Xeo786 » 05 Aug 2022, 01:37

noorudin wrote:
04 Aug 2022, 05:09
trying to access the [clear data](as 0 and 4 indicated) button inside the [clear browsing data] in the settings page of chrome, steps to indication 2 were fine, but failed at the indication 3.(as below screenshot)
settings.png
the code went wrong to the indication 3. as showing below

Code: Select all

#SingleInstance, force
#Include %A_ScriptDir%\Rufaydium.ahk
{	; ** ChromeDriver **
	Browser:=new Rufaydium()
	Page:=Browser.NewSession()
}
	Page.Navigate("chrome://settings/privacy")
	If IsObject(Page){
		elem:=Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow().querySelector("#basicPage").querySelector("settings-section:nth-child(9)").querySelector("settings-privacy-page").shadow().querySelector("settings-clear-browsing-data-dialog")
		MsgBox,,, % json.dump(elem)
	}

Page.Quit()
Page.Close()

Browser.QuitAllSessions()
Browser.Exit()
return
the wrong message showing below:
step_3.png
if I commented the last querySelector, like this:

Code: Select all

elem:=Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow().querySelector("#basicPage").querySelector("settings-section:nth-child(9)").querySelector("settings-privacy-page").shadow()
;.querySelector("settings-clear-browsing-data-dialog")
I can access the shadow-root, as showing below:
step_2.png
if I commented the last shadow(), like this:

Code: Select all

elem:=Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow().querySelector("#basicPage").querySelector("settings-section:nth-child(9)").querySelector("settings-privacy-page")
;.shadow()
I cad access the "settings-privacy-page" element as well.
I had try it many times but always failed at indication 3.
could someone know what's wrong with me or else? :crazy: :cry: :headwall:
You need to look carefully into html tree while dealing with the shadow, I have pointed out where you missed trail.

Code: Select all

; no need to do it one line you cannot test it in chrome console so you need to go step by step storing every element into a variable and checking while debugging.
elem := Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow()
; .querySelector("#basicPage") ; skipping  coz we do not need to get to #basicPage

; using querySelectorAll instead to get all settings-section and stored array[4] into variable
elem := elem.querySelectorAll("settings-section")[4] 
elem  := elem.querySelector("settings-privacy-page").shadow()
elem := elem.querySelector("settings-clear-browsing-data-dialog").shadow()
elem := elem.querySelector("cr-dialog") ; .shadow() no need switch shadow here
elem := elem.querySelector("#clearBrowsingDataConfirm")
msgbox, % "press on to click that button `nyou got html: `n" elem.outerhtml 
elem.click() ;will press the button
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

noorudin
Posts: 3
Joined: 24 Dec 2020, 04:01

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by noorudin » 05 Aug 2022, 03:30

@Xeo786
Ah~! I'm a newbie, I'm learning on Rufaydium hardly, my brother! thanks!
as newbie, I can't reply Ur private message, coz the rule of this forum.
I'm from Taiwan, my borther. Salam!

noorudin
Posts: 3
Joined: 24 Dec 2020, 04:01

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by noorudin » 05 Aug 2022, 04:51

@Xeo786
following ur code, steps to:

Code: Select all

elem := Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow()
elem := elem.querySelectorAll("settings-section")[4] 
elem := elem.querySelector("settings-privacy-page").shadow()
were fine for both Urs and mine,then next went wrong:

Code: Select all

elem := elem.querySelector("settings-clear-browsing-data-dialog")
the error occured, was same with mine(as u can see step_3.png of my post) in AHK.
sorry!

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 05 Aug 2022, 05:05

noorudin wrote:
05 Aug 2022, 04:51
@Xeo786
following ur code, steps to:

Code: Select all

elem := Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow()
elem := elem.querySelectorAll("settings-section")[4] 
elem := elem.querySelector("settings-privacy-page").shadow()
were fine for both Urs and mine,then next went wrong:

Code: Select all

elem := elem.querySelector("settings-clear-browsing-data-dialog")
the error occured, was same with mine(as u can see step_3.png of my post) in AHK.
sorry!
following code is working for me may be I am using url that searches for 'clearBrowserData', that might be changing HTML

Code: Select all

Page := GetRufaydium("chrome://settings/clearBrowserData?search=clear")
elem := Page.querySelector("settings-ui").shadow().querySelector("#main").shadow().querySelector("settings-basic-page").shadow()
elem := elem.querySelectorAll("settings-section")[4]
elem  := elem.querySelector("settings-privacy-page").shadow()
elem := elem.querySelector("settings-clear-browsing-data-dialog").shadow()
elem := elem.querySelector("cr-dialog")
elem := elem.querySelector("#clearBrowsingDataConfirm")
elem.click() 
return

f12::
Chrome := new Rufaydium() 
Chrome.QuitAllSessions() ; close all session 
Chrome.Driver.Exit() ; then exits driver
msgbox, all session closed and Driver Exitted
return

; GetRufaydium(URL) gets existing session  
; stops us creatting multiple sessions again and again 
; make sure do not manually close driver / chrome.driver.exit()
; by Xeo786
GetRufaydium(URL)
{
	; get chrome driver / runs chrome driver if not running, download driver if available in A_ScriptDir
	; Run Chrome Driver with default parameters and loads deafult capabilities
	Chrome := new Rufaydium() 
	Page := Chrome.getSessionByUrl(URL) ; check page (created by driver) if already exist 
	if !isobject(page) ; checcking if Session with url exist
	{
		Page := Chrome.getSession(1,1) ; try getting first session first tab
		if isobject(page) ; if exist 
			Page.NewTab() ; create new tab instead new session
		else ; if does not exist 
			Page := Chrome.NewSession() ; create new session ; Page.Exit() if any session manually closed by user which causes lag
		Page.Navigate(URL) ; navigate		
	}
	return page 
}

"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by safetycar » 05 Aug 2022, 05:38

I'm not sure if it's worth to point this out... Maybe so that the author knows, in case of someone reports problems.
But the unzipping method can fail if you have gone out of windows way and disabled the integration of zip folders in the registry.
Probably an uncommon thing to do.
(In such case there's a namespace error for this.zip and you need to extract the content of the zip before file gets deleted, or you have to find another zip yourself)

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 05 Aug 2022, 06:34

safetycar wrote:
05 Aug 2022, 05:38
I'm not sure if it's worth to point this out... Maybe so that the author knows, in case of someone reports problems.
But the unzipping method can fail if you have gone out of windows way and disabled the integration of zip folders in the registry.
Probably an uncommon thing to do.
(In such case there's a namespace error for this.zip and you need to extract the content of the zip before file gets deleted, or you have to find another zip yourself)
Rufaydium also uses WinHttp COM a lot, it's even based on RESTful apis, I wonder if someone has disabled WinHTTP COM and is willing to use dllcall instead, it will make this simple library overcomplicated, :think: anyway.

if you have a third-party extractor and you know how to extract stuff using AHK. then you make personalize changes accordingly into DownloadnExtract() method in WDM.ahk (Web Driver Managment).

hope it will help.
"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.7.0 (no selenium/websocket)

Post by Milchmann » 05 Aug 2022, 06:45

Hi @Xeo786 ,

I have come a long way in rewriting my code from Selenium to Rufaydium. It runs very stable. Thanks for your work so far!

But what still doesn't work is
DoubleClickand contextmenu.

Eventlisteners for them are available (see picture).
grafik.png
grafik.png (18.6 KiB) Viewed 2917 times

Code: Select all

	E := driver.QuerySelector("#T0444333 > tbody > tr:nth-child(5)").doubleClick()
	if % e.Error
		MsgBox % e.Error
I get the error message:
unknown command
Lately I get with

Code: Select all

E := driver.cdp.Evaluate("document.querySelector('#keywords').click();")
no reaction either, but also no error message.

Code: Select all

driver.QuerySelector("#keywords").click()
works

What am I doing wrong here?

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 05 Aug 2022, 07:28

Milchmann wrote:
05 Aug 2022, 06:45
But what still doesn't work is
DoubleClick and contextmenu.

Code: Select all

	E := driver.QuerySelector("#T0444333 > tbody > tr:nth-child(5)").doubleClick()
	if % e.Error
		MsgBox % e.Error
I would like you to try

Code: Select all

driver.QuerySelector("#T0444333 > tbody > tr:nth-child(5)").Execute("var evObj = new MouseEvent('dblclick', {bubbles: true, cancelable: true, view: window});arguments[0].dispatchEvent(evObj);")
Milchmann wrote:
05 Aug 2022, 06:45

Code: Select all

driver.QuerySelector("#keywords").click()
try same thing

Code: Select all

driver.QuerySelector("#keywords").Execute("arguments[0].click()")
I have no clue how to trigger the context menu till now.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by safetycar » 05 Aug 2022, 07:35

@Xeo786 So it was not worth pointing out :lol: . I guess I posted to let others know because it was the first thing I saw trying to set it up, but I didn't expect a big change.
For the rest, I haven't seen much yet but it's looking good. :thumbup:

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Milchmann » 05 Aug 2022, 08:27

Xeo786 wrote:
05 Aug 2022, 07:28
Milchmann wrote:
05 Aug 2022, 06:45
But what still doesn't work is
DoubleClick and contextmenu.

Code: Select all

	E := driver.QuerySelector("#T0444333 > tbody > tr:nth-child(5)").doubleClick()
	if % e.Error
		MsgBox % e.Error
I would like you to try

Code: Select all

driver.QuerySelector("#T0444333 > tbody > tr:nth-child(5)").Execute("var evObj = new MouseEvent('dblclick', {bubbles: true, cancelable: true, view: window});arguments[0].dispatchEvent(evObj);")
Does not work and no errors

Post Reply

Return to “Scripts and Functions (v1)”