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

Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 11 Apr 2022, 07:21

Image
Rufaydium

Rufaydium is Webdriver Library that can support any chromium-based browser, It only requires Latest WebDriver,
it can download the latest driver and update the driver according to the web browsers version,
this ability is available for Chrome and MS Edge web browsers for now.

It utilizes Rest Api of W3C from https://www.w3.org/TR/webdriver2/
Rufaydium also supports Chrome Devtools Protocols same as chrome.ahk

Note: no need to install / setup selenium, Rufaydium is AHK's Selenium,
even Selenium 4 has not been implemented with the latest W3C Webdriver methods for many languages,
I am not a user of Selenium therefore, I am not sure if Rufaydium has more functionality compared to selenium
but I am sure Rufaydium is more flexible than selenium

Please feel free to point out issues or suggest functionality
I want you to Test Firefox, Edge, or any other Chromium based Web browser
I am planning to test them as soon as I get free time

Example
We can use all DOM methods of getting element, return element / element array, and that array is AHK array having class objects

Code: Select all

#Include Rufaydium.ahk
f1::
Chrome := new Rufaydium() ; this will return control over Chrome Browser
Page := Chrome.NewSession() ; creating session
Page.url :=  "https://www.autohotkey.com/boards/" ; can also use page.navigate(url)
Page.getElementByID("keywords").sendkey("Rufaydium`n") ; accessing element and sending keys
return

f12:: ; close all sessions first then exit the driver
Chrome := new Rufaydium() ; accessing browser
Chrome.QuitAllSessions() ; closing all session one by one
Chrome.driver.exit() ; exitting driver
return
Rufaydium Supports Following drivers so far

Code: Select all

Chrome := new Rufaydium() ; will Download/Load Chrome driver as "chromedriver.exe" is default DriverName
MSEdge := new Rufaydium("msedgedriver.exe","--port=9516") ; will Download/Load MS Edge driver comunication port will be 9516
FireFox := new Rufaydium("geckodriver.exe") ; will Download/Load geckodriver for FireFox
opera := new Rufaydium("operadriver.exe") ; will Download/Load operadriver
Continue Existing Sessions
Rufaydium does not exit the driver if the script is terminated, previously running driver can be accessed using the following methods, or multiple scripts can access one specific driver for automation,

Code: Select all

Chrome := new Rufaydium("chromedriver.exe")
Session := Chrome.NewSession()
Session := Chrome.getSession(1) ; this will return with Session by number sequencing from first created to latest created
Session := Chrome.getSession(1,2) ; this will return with first session and switch Second tab, Tabs count from left to right
Session := Chrome.getSessionByUrl(URL)
Session2 := Chrome.getSessionByTitle(Title)
Note: above methods are based on the httpserver\sessions command which is not W3C standard, but Rufaydium uses ahk's functions readini, writeini & deleteini, to store and parse Session IDs, therefore getSessionByUrl() & getSessionByTitle() now support firefox session, this way Rufadium has the ability to continue geckodriver Sessions, or multiple AHK scripts can contorl firefox by sharing ActiveSessions.ini which records/delete sessionids at A_ScriptDir, hence that ini should be shared in such way in case scripts are being run from a different folder, in future update sharing ActiveSessions.ini will be no issue as I just had an idea.
Read Readme.md on Git for more
GitHub
Releases
Download Main
Whats New

You can use any driver by downloading manually and they should work fine concerned browser version according to W3C standards.
Last edited by Xeo786 on 04 Nov 2022, 02:10, edited 55 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 (no selenium/websocket)

Post by Xeo786 » 12 Apr 2022, 00:11

Last edited by Xeo786 on 14 May 2022, 11:07, edited 6 times in total.
"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 (no selenium/websocket)

Post by Milchmann » 14 Apr 2022, 07:42

:bravo: :bravo: :bravo:

Thank you, that is already very good.
I will try it next week, but I can say that various things already work.

Some things do not work yet, but I'll write that down and ask.

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 14 Apr 2022, 10:02

Waiting for your reply 🤗
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Rufaydium WebDriver (no selenium/websocket)

Post by tank » 14 Apr 2022, 10:50

Impressive work. I am so happy that you separated out dev tools and wrapped many of the basic web driver calls to be used with common DOM methods
This is my new goto library
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 15 Apr 2022, 08:10

tank wrote:
14 Apr 2022, 10:50
Impressive work. I am so happy that you separated out dev tools and wrapped many of the basic web driver calls to be used with common DOM methods
This is my new goto library
Thank you :)
Soon I would post few examples for about Session.CDP
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Tre4shunter
Posts: 139
Joined: 26 Jan 2016, 16:05

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Tre4shunter » 15 Apr 2022, 10:33

Very impressive work!

Have been playing with it, only thing so far which you state in the example isn't fully working yet for whatever reason is printtopdf.
If anyone is able to sort that, i'd be grateful! If I come across a solution as well I will let you know.

Thanks!

gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Rufaydium WebDriver (no selenium/websocket)

Post by gregster » 15 Apr 2022, 12:10

Tre4shunter wrote:
15 Apr 2022, 10:33
Have been playing with it, only thing so far which you state in the example isn't fully working yet for whatever reason is printtopdf.
Not sure if related, but if I remember correctly the Chrome Debugging Protocol used to support printing to PDF only in headless mode.

Tre4shunter
Posts: 139
Joined: 26 Jan 2016, 16:05

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Tre4shunter » 15 Apr 2022, 12:21

@gregster

That is correct - The process here is essentialyl the same, and i modified the config to include the --headless switch, but to no avail. so, its got to be something else.

Using --headless did in fact start it 'hidden' properly, but the printtopdf method didnt work still.

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 15 Apr 2022, 16:22

Tre4shunter wrote:
15 Apr 2022, 12:21
@gregster
Using --headless did in fact start it 'hidden' properly, but the printtopdf method didnt work still.
there were few flaws in code session.print() to pdf is working fine in headless mode,
I read about it, that only headless mode support printtopdf but that kind of weird who wana print without preview.
headless mode run session without UI or hidden :think:
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by ahk7 » 16 Apr 2022, 02:21

General question: So can you use Rufaydium to replace IE COM? I've never been able to get Chrome.ahk running (my fault no doubt)?

With the impending demise of Internet Explorer I'm looking into a replacement method for semi-manual/automatic data entry. My current setup with IE consists of an AutoHotkey Gui floating atop IE where I can see which record I'm about to process (data in listview) and make some changes that set values in radio/check/select tags before setting the values in the browser, save it and proceed to the next.

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 16 Apr 2022, 03:27

ahk7 wrote:
16 Apr 2022, 02:21
General question: So can you use Rufaydium to replace IE COM?
Yes I am switching to Rufaydium bit by bit there are lot of codes I am still using COM IE,
ahk7 wrote:
16 Apr 2022, 02:21
I've never been able to get Chrome.ahk running (my fault no doubt)?
Chrome.ahk inspired me to write Rufaydium
Selenium did not worked for me there are few reasons like stubbornness, little bid new syntax, confusing error handling or I might never understand how does Selenium works, unlike selenium chrome.ahk written in pure AHK, and reading through code and CDP I learned a lot.
I wonder where you stuck using chrome.ahk is it JS ? because I need to learn little bit JS or it was user profile setup?
ahk7 wrote:
16 Apr 2022, 02:21
With the impending demise of Internet Explorer I'm looking into a replacement method for semi-manual/automatic data entry. My current setup with IE consists of an AutoHotkey Gui floating atop IE where I can see which record I'm about to process (data in listview) and make some changes that set values in radio/check/select tags before setting the values in the browser, save it and proceed to the next.
I suggest you Go for Rufaydium :) all you need to do is learn few new tricks and rules.
Spoiler
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Eik
Posts: 9
Joined: 26 Feb 2020, 20:53

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Eik » 16 Apr 2022, 21:56

;Translated

Hello!
I just wanted to relearn Chrome automation.

Rufaydium's cdp allows you to use code created using Chrome.ahk without modification.
If this becomes known, many people will be interested in Rufaydium.

Code: Select all

class classChrome
{
	__new(){
		this.ProfilePath := ""
		Arg_Profile      := "--user-data-dir=" this.ProfilePath
		Arg_option       := "--headless"

		;【Chrome.ahk】―――――――――――――――――
		;this.ChromeInst   := new Chrome(Arg_Profile,,Arg_option)
		;this.PageInstance := this.ChromeInst.GetPage()
		;―――――――――――――――――――――――――

		;【Rufaydium】―――――――――――――――――
		ChromeDriver := A_ScriptDir "\chromedriver.exe"

		this.Driver       := new RunDriver(ChromeDriver)
		this.ChromeInst   := new Rufaydium(this.Driver)
		;o := example_Rufaydium_CmdLineArg(Arg_Profile,Arg_option)
		;this.ChromeInst.SessionParameters(o)
		this.Page1        := this.ChromeInst.NewSession()
		this.PageInstance := this.Page1.cdp
	}
	OpenUrl(url){
			this.PageInstance.Call("Page.navigate", {"url": url})
			this.PageInstance.WaitForLoad()
	}
	SetBlockImage(){
		ExtList := ["*.ttf","*.gif" , "*.png" , "*.jpg" , "*.jpeg" , "*.webp"]
		this.PageInstance.call("Network.enable")
		this.PageInstance.call("Network.setBlockedURLs",{"urls": ExtList })
	}
}

example_Rufaydium_CmdLineArg(arg*){
	o =
	( LTrim Join c
	{
		"capabilities": {
			"alwaysMatch": {
				"browserName": "chrome",
				"platformName": "windows",
				"goog:chromeOptions": {
					"w3c": {"name":"true","value":1},
					;"args": ["--headless"],
					"excludeSwitches": ["enable-automation"]
				}
			},
			"firstMatch": [{}]
		},
		"desiredCapabilities": {
			"browserName": "chrome"
		}
	}
	)
	o := json.Load(o)
	i := 1
	For _ , v in arg
		If  v
			o.capabilities.alwaysMatch["goog:chromeOptions"].args[i++] := v

	Return	o
}
I'm glad to be able to do so many things with AutoHotkey.
Thank you Xeo786!

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by ahk7 » 17 Apr 2022, 03:49

More is happening already with Rufaydium then with chrome.ahk so that is good.

As I have to deal with frames would anybody happen to know how to rewrite "IE COM":
wb.document.parentwindow.frames("content").document.all.qfield1.value := "user123"
where
content is the name of the target frame
qfield1 is the ID of the input field in that frame I'm trying to set
to this new format? Once I have that, I can no doubt figure out other input types.

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 18 Apr 2022, 02:47

ahk7 wrote:
17 Apr 2022, 03:49
As I have to deal with frames would anybody happen to know how to rewrite "IE COM":
wb.document.parentwindow.frames("content").document.all.qfield1.value := "user123"
where
content is the name of the target frame
qfield1 is the ID of the input field in that frame I'm trying to set
to this new format? Once I have that, I can no doubt figure out other input types.
We Switch Tabs using Session.SwitchbyTitle(Title) or Seesion.SwitchbyURL(url="")
but Session remain the same If you check out examples I posted you would easly understand how switching Tab works
Just like Switch Tabs one can Switch Frames as well and pointer session will remain same.

Image

Code: Select all

; according to above image we have 1 session having three tabs
Session.SwitchbyURL(tab1url) ; to switch to TAB 1
; tab 1 has total 3 Frame
msgbox, % Session.FramesLength() ; this will return Frame quantity 2 from Main frame 
Session.Frame(0) ; switching to frame A
Session.getelementbyid(someid) ; this will get element from frame A
; now we cannot switch to frame B directly we need to go to main frame / main page
Session.ParentFrame() ; switch back to parent frame
Session.Frame(1) ; switching to frame B
Session.getelementbyid(someid) ; this will get element from frame B
; frame B also has a nasted frame we can switch to frame BA because its inside frame B
Session.Frame(0) ; switching to frame BA
Session.getelementbyid(someid) ; this will get element from frame BA
Session.ParentFrame() ; switch back to Frame B
Session.ParentFrame() ; switch back to Main Page / Main frame
Now Tab 2

Code: Select all

; according to above image we have 1 session having three tabs
Session.SwitchbyURL(tab2url) ; to switch to TAB 2
; tab 1 also has total 3 frames
msgbox, % Session.FramesLength() ; this will return Frame quantity 3
Session.Frame(0) ; switching to frame X
Session.ParentFrame() ; switch back to Main Page / Main frame
Session.Frame(1) ; switching to frame Y
Session.ParentFrame() ; switch back to Main Page / Main frame
Session.Frame(2) ; switching to frame Z
Session.ParentFrame() ; switch back to Main Page / Main frame
Tab 3

Code: Select all

; according to above image we have 1 session having three tabs
Session.SwitchbyURL(tab3url) ; to switch to TAB 3
msgbox, % Session.FramesLength() ; this will return Frame quantity which is Zero because TAB 3 has no frame 
I hope this would help.
I have not tested it but I am sure Switching frame would also Switch CDP of that Frame, which mean after switching to specific frame we can then able to modify its DOM using CDP
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by ahk7 » 18 Apr 2022, 03:45

Xeo786 wrote:
18 Apr 2022, 02:47
I hope this would help.
It sure does, I'm getting somewhere with this. Many thanks. :thumbup:

I would encourage you to post this code on say github and include documentation there as well, what I found in the past is that this is a difficult subject for many and that clear code examples are often scattered through very long threads making it all the more complicated. The images you prepared for the frames above are very helpful for example.

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 18 Apr 2022, 06:57

ahk7 wrote:
18 Apr 2022, 03:45
Xeo786 wrote:
18 Apr 2022, 02:47
I hope this would help.
It sure does, I'm getting somewhere with this. Many thanks. :thumbup:

I would encourage you to post this code on say github and include documentation there as well, what I found in the past is that this is a difficult subject for many and that clear code examples are often scattered through very long threads making it all the more complicated. The images you prepared for the frames above are very helpful for example.
I just made github account and share Rufaydium look at first post for the link
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by ahk7 » 18 Apr 2022, 08:56

Perfect :thumbup:
I've added Rufaydium WebDriver to https://github.com/ahkscript/awesome-AutoHotkey/#networking

User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Rufaydium WebDriver (no selenium/websocket)

Post by tank » 18 Apr 2022, 09:43

ahk7 wrote:
16 Apr 2022, 02:21
So can you use Rufaydium to replace IE COM?
tank wrote:
14 Apr 2022, 10:50
Impressive work. I am so happy that you separated out dev tools and wrapped many of the basic web driver calls to be used with common DOM methods
This is my new goto library
I see now that i have been out of the limelight on browser automation too long. As someone that authored tutorials and produced several libraries on IE and COM I kinda implied this was going to be my exit from IE,

You can still use IE COM with edge in IE mode. But i am really not in the mood to expand on preserving methods like that since there are issues with many modern DOM methods that will never be resolved now. I hav an IE library class i have used a long time that I am merely replacing the contents of the methods of with redirected calls to Rufaydium so that the move to chrome can be seemless for my existing automations. (so glad i started practicing code abstraction years ago )


@Xeo786 I find your manner of presenting answers and supporting answers some how obvious but yet I have never seen any one do it that way. It is uniquely noob friendly on a subject that has confounded noobs for a very long time.
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 18 Apr 2022, 11:44

tank wrote:
18 Apr 2022, 09:43
@Xeo786 I find your manner of presenting answers and supporting answers some how obvious but yet I have never seen any one do it that way. It is uniquely noob friendly on a subject that has confounded noobs for a very long time.
I consider myself noob, because AHK is my first programing language that I learned here through this forum, IRC and later discord.
A noob can define complicated stuff simply by learning and facing those difficulties.
"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)”