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

Post by Xeo786 » 22 Apr 2022, 01:19

ahk7 wrote:
21 Apr 2022, 12:20
.innertext works, but how do you get the .OuterHTML? Not that I directly need it but would be useful to have to be able to inspect and debug I think (I do see OuterHTML in CDP.ahk)
Yah Rudaydium Basic Session is just act like human interaction with web page. CDP Session Session.CDP.methods can modify Whole DOM

Code: Select all

Session.CDP.Document() ; https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument
; now we can do getelement from CDP
tables := Session.CDP.querySelectorAll("table")
for i, table in tables
	msgbox, % table.outerhtml ; we can also modify this html using Session.CDP.setOuterHTML(Htmlstring)
"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 » 22 Apr 2022, 02:44

Yah Rudaydium Basic Session is just act like human interaction with web page. CDP Session Session.CDP.methods can modify Whole DOM

Code: Select all

GS.SwitchbyTitle("GitHub - Xeo786/Rufaydium-Webdriver: Rufaydium is Webdriver Library for Autohotket, can support any chromium based browser and only requires Latest WebDriver")

GS.CDP.Document() ; https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument
; now we can do getelement from CDP

check:= GS.CDP.querySelectorAll("H3")
for i, h3 in check
	msgbox, % h3.outerhtml


:bravo:

Super work, thank you

I still need :
GS.CDP.querySelectorAll("H3").length


Is this possible?

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 22 Apr 2022, 02:57

Milchmann wrote:
22 Apr 2022, 02:44

I still need :
GS.CDP.querySelectorAll("H3").length


Is this possible?

Code: Select all

GS.CDP.querySelectorAll("H3").length() ; this would work
"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 » 22 Apr 2022, 03:04

Tre4shunter wrote:
21 Apr 2022, 10:10
using "--log-PATH=c:\myfile.log --enable-chrome-logs" does work to log the console messages from a web page...but whenever I add those two switches, for some reason it continuously pops up multiple cmd windows for chrome.exe which are blank.

I've not yet figured out how to prevent those cmd windows from appearing wen using the above switches...
according to following link, including these switched in capabilities may create log file
https://peter.sh/experiments/chromium-command-line-switches/#log-file

Code: Select all

	static ChromeLogs =
	( LTrim Join
	{
	"capabilities": {
		"alwaysMatch": {
			"browserName": "chrome",
			"platformName": "windows",
			"goog:chromeOptions": {
				"w3c": json.true,
				"excludeSwitches": ["--log-file=c:\myfile.log","--log-level=0"]
			}
		},
		"firstMatch": [{}]
		},
	"desiredCapabilities": {
		"browserName": "chrome"
		}
	}
"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 » 22 Apr 2022, 05:08

Xeo786 wrote:
22 Apr 2022, 02:57
Milchmann wrote:
22 Apr 2022, 02:44

I still need :
GS.CDP.querySelectorAll("H3").length


Is this possible?

Code: Select all

GS.CDP.querySelectorAll("H3").length() ; this would work
Thank you, works.

Another question. I have several computers where the path changes every time I start and restart the program.


Is there a way to determine the user and then enter this path in static ChromeProfile ?


For example:

Code: Select all

static ChromeProfile =
	( LTrim Join
	{
		"args": ["--user-data-dir=C:/xxx/Profile"],
	}	
or

Code: Select all

static ChromeProfile =
	( LTrim Join
	{
		"args": ["--user-data-dir=C:/yyy/Profile"],
		
	}
Thank you

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 22 Apr 2022, 06:16

Milchmann wrote:
22 Apr 2022, 05:08
Is there a way to determine the user and then enter this path in static ChromeProfile ?

Code: Select all

static ChromeProfile =
	( LTrim Join
	{
		"args": ["--user-data-dir=C:/%a_username%/Profile"],
	}
	)
I think it should be C:/Users/%a_username%/Profile
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

thalesduarte
Posts: 95
Joined: 13 Sep 2021, 06:08

Re: Rufaydium WebDriver (no selenium/websocket)

Post by thalesduarte » 22 Apr 2022, 07:02

@Xeo786, Do you have any basic example, writing and click at button using that library?
Thanks for the help.

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 22 Apr 2022, 07:07

thalesduarte wrote:
22 Apr 2022, 07:02
@Xeo786, Do you have any basic example, writing and click at button using that library?
Thanks for the help.
https://github.com/hi5/Rufaydium-Webdriver#how-to-use
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

thalesduarte
Posts: 95
Joined: 13 Sep 2021, 06:08

Re: Rufaydium WebDriver (no selenium/websocket)

Post by thalesduarte » 22 Apr 2022, 07:47

Xeo786 wrote:
22 Apr 2022, 07:07
thalesduarte wrote:
22 Apr 2022, 07:02
@Xeo786, Do you have any basic example, writing and click at button using that library?
Thanks for the help.
https://github.com/hi5/Rufaydium-Webdriver#how-to-use
I'm trying to do like this but dont work :(

Code: Select all

#Include Rufaydium.ahk
; Just need WebDriver Executable location 
ChromeDriver := A_ScriptDir "\chromedriver.exe"
; choose different driver in order to automate different Browser
Driver := new RunDriver(ChromeDriver) ; running driver
Chrome := new Rufaydium(Driver) ; this will return control over Browser

; choosing Browser Capabilities, by using Capabilities Class you can make custom profile for specific need
; Chrome.capabilities := Capabilities.ChromeDefault 

; this is how we create session 
Page := Chrome.NewSession()
Page.Navigate("https://www.autohotkey.com/boards/")

Page := ""
return

f3::
Element := Page.getElementsbyXpath("//*[@id=""keywords""]")
msgbox %Element%
The script open the chrome and website, but dont print keywords when i type in the form and press f3

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 22 Apr 2022, 09:31

thalesduarte wrote:
22 Apr 2022, 07:47
Xeo786 wrote:
22 Apr 2022, 07:07
thalesduarte wrote:
22 Apr 2022, 07:02
@Xeo786, Do you have any basic example, writing and click at button using that library?
Thanks for the help.
https://github.com/hi5/Rufaydium-Webdriver#how-to-use
I'm trying to do like this but dont work :(

Code: Select all

#Include Rufaydium.ahk
; Just need WebDriver Executable location 
ChromeDriver := A_ScriptDir "\chromedriver.exe"
; choose different driver in order to automate different Browser
Driver := new RunDriver(ChromeDriver) ; running driver
Chrome := new Rufaydium(Driver) ; this will return control over Browser

; choosing Browser Capabilities, by using Capabilities Class you can make custom profile for specific need
; Chrome.capabilities := Capabilities.ChromeDefault 

; this is how we create session 
Page := Chrome.NewSession()
Page.Navigate("https://www.autohotkey.com/boards/")

Page := ""
return

f3::
Element := Page.getElementsbyXpath("//*[@id=""keywords""]")
msgbox %Element%
The script open the chrome and website, but dont print keywords when i type in the form and press f3
Element which is return is class object you can try any element.method something like element.value or element.innertext
Getting element with xpath return with element array so

Code: Select all

Elements := Page.getElementsbyXpath("//*[@id=""keywords""]")
For I, element in Elements
     Msgbox % element.innertext
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

thalesduarte
Posts: 95
Joined: 13 Sep 2021, 06:08

Re: Rufaydium WebDriver (no selenium/websocket)

Post by thalesduarte » 22 Apr 2022, 12:58

Xeo786 wrote:
22 Apr 2022, 09:31
thalesduarte wrote:
22 Apr 2022, 07:47
Xeo786 wrote:
22 Apr 2022, 07:07
thalesduarte wrote:
22 Apr 2022, 07:02
@Xeo786, Do you have any basic example, writing and click at button using that library?
Thanks for the help.
https://github.com/hi5/Rufaydium-Webdriver#how-to-use
I'm trying to do like this but dont work :(

Code: Select all

#Include Rufaydium.ahk
; Just need WebDriver Executable location 
ChromeDriver := A_ScriptDir "\chromedriver.exe"
; choose different driver in order to automate different Browser
Driver := new RunDriver(ChromeDriver) ; running driver
Chrome := new Rufaydium(Driver) ; this will return control over Browser

; choosing Browser Capabilities, by using Capabilities Class you can make custom profile for specific need
; Chrome.capabilities := Capabilities.ChromeDefault 

; this is how we create session 
Page := Chrome.NewSession()
Page.Navigate("https://www.autohotkey.com/boards/")

Page := ""
return

f3::
Element := Page.getElementsbyXpath("//*[@id=""keywords""]")
msgbox %Element%
The script open the chrome and website, but dont print keywords when i type in the form and press f3
Element which is return is class object you can try any element.method something like element.value or element.innertext
Getting element with xpath return with element array so

Code: Select all

Elements := Page.getElementsbyXpath("//*[@id=""keywords""]")
For I, element in Elements
     Msgbox % element.innertext
Dont work, returns blank text box :(

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by ahk7 » 22 Apr 2022, 14:46

Xeo786 wrote:
22 Apr 2022, 01:19
CDP Session Session.CDP.methods can modify Whole DOM
:thumbup: CDP does the trick.

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by ahk7 » 22 Apr 2022, 15:12

thalesduarte wrote:
22 Apr 2022, 12:58
Dont work, returns blank text box :(
1. You clear page:="" in your F1 hotkey so you lose the session there already, that is never going to work
2. I don't think you can get the value of a input before you've submitted it - at least not that I know, if the page has loaded, the value of the keywords input is empty of course. (Not saying it can't be done, but I simply don't know how)

Try this script, it starts chromium and shows a message box, but enter some keywords in the ahk search box first and hit enter to search - THEN press OK, now the msgbox should show they keywords you have entered. For me it does anyway.

Code: Select all

#SingleInstance, force
#Include %A_ScriptDir%\lib
#Include Rufaydium.ahk

ChromeDriver := A_ScriptDir "\chromedriver.exe"

url:="https://www.autohotkey.com/boards/"


; choose different driver in order to automate different Browser
Driver := new RunDriver(ChromeDriver) ; running driver
Chrome := new Rufaydium(Driver) ; this will return control over Browser

; choosing Browser Capabilities, by using Capabilities you can make custom profile for specific need
Chrome.capabilities := Capabilities.ChromeDefault 

; this is how we create session 
Page := Chrome.NewSession()
Page.Navigate(url)

GS := Chrome.getSessionByUrl(url)

MsgBox, Enter keywords, start search, wait for results, press OK

Element := GS.getElementsbyXpath("//*[@id=""keywords""]")

msgbox, % element[1].value

GS:=""
Page := ""

Chrome.QuitAllSessions()
driver.exit()

ExitApp
Alternative method would be to copy it to the clipboard :D

Code: Select all

element:=GS.getElementbyID("keywords")
Element.SendKey(key.ctrl "a")
Element.SendKey(key.ctrl "c")
Sleep 100
MsgBox % clipboard

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 23 Apr 2022, 04:12

I was testing Session.actions() and I just want to share that piece of code

sketch.io example
Following code will try to select line as pencil and then it will draw Pentagon

Code: Select all

f1::
Chrome := new Rufaydium() ; this will return control over Browser
Chrome.Driver.visible := true ; make Driver CMD window visible 
Page := Chrome.getSessionByUrl("https://sketch.io/sketchpad/") ; try to get if already there
; we can also do getSessionByTitle(title)
if !IsObject(Page) ; checking if page found or not 
{
	Page := Chrome.NewSession() ; creating new session 
	Page.Navigate("https://sketch.io/sketchpad/")
	msgbox, close all messages on sketch.io and press f1 again
	return
}
Page.querySelectorAll("sketch-tool")[3].click() ; click on pencil icon
while !Page.QuerySelectorAll("sketch-gridviewtrigger")[1].displayed() ; wait for menu to get visible using dropdown element visibility 
	sleep, 200
Page.QuerySelectorAll("sketch-gridviewtrigger")[1].click() ; click on dropdown

; looping through types of pencils and selecting "line" 
for i, pencil in Page.QuerySelectorAll("sketch-popoutcontent")[2].QuerySelectorAll("sketch-griditem")
{
	if instr(pencil.innerText,"line")
	{
		pencil.click()
	}
}
while Page.QuerySelectorAll("sketch-gridviewtrigger")[1].displayed()  ; we wait for menu to disappear 
{
	Page.querySelectorAll("sketch-tool")[3].click() ; click will make it disappear so we are clicking, 500 ms delay may be enough
	sleep, 500
}
; defining Actionobject
Pentagon =
( LTrim Join
{
"actions": [
	{
	"type": "pointer",
	"id": "mouse",
	"parameters": {"pointerType": "mouse"},
	"actions": [
		{"type": "pointerDown", "button": 0},
		{"type": "pointerMove", "duration": 10,"x":288, "y":258},
		{"type": "pointerMove", "duration": 10,"x":391, "y":181},
		{"type": "pointerMove", "duration": 10,"x":493, "y":258},
		{"type": "pointerMove", "duration": 10,"x":454, "y":358},
		{"type": "pointerMove", "duration": 10,"x":328, "y":358},
		{"type": "pointerMove", "duration": 10,"x":288, "y":258},
		{"type": "pointerUp", "button": 0}
		]
		}
	]
}
)
page.actions(json.load(Pentagon)) ; initiate actions 
return
Result
Image
Last edited by Xeo786 on 10 May 2022, 07:59, edited 2 times in total.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Rufaydium WebDriver (no selenium/websocket)

Post by aifritz » 23 Apr 2022, 08:34

If I have already logged in to a website with my credentials, is there a way to connect to that browser session that is already open?

Many thanks to Xeo786 for this great work! I am deeply impressed :bravo:

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 24 Apr 2022, 23:51

aifritz wrote:
23 Apr 2022, 08:34
If I have already logged in to a website with my credentials, is there a way to connect to that browser session that is already open?
If you have logged into a website that is opened without webdriver you cannot access that session. You can only access session created through webdriver until webdriver restarts, after driver.exit() you will not be able to access those sessions created by webdriver.
https://github.com/Xeo786/Rufaydium-Webdriver#script-reloading

I am really into accessing all session which are not created through webdriver and I accidentally manage to do that multiple times, until chrome 100, after chrome 100 I do not face those accidents and I am still curious why and how that happened but still I haven't found any reason.

Code: Select all

; until chrome 100 sometimes/accidentally it return with all the browser sessions even with session not created with webdriver 
Session.getSessions() 

I don't know its security breach or something else but now chrome 100 do not commit that type of mistakes, well it was useful though.
"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 » 25 Apr 2022, 03:12

Xeo786 wrote:
22 Apr 2022, 06:16
Milchmann wrote:
22 Apr 2022, 05:08
Is there a way to determine the user and then enter this path in static ChromeProfile ?

Code: Select all

static ChromeProfile =
	( LTrim Join
	{
		"args": ["--user-data-dir=C:/%a_username%/Profile"],
	}
	)
I think it should be C:/Users/%a_username%/Profile
Does not work :

Code: Select all

 "args": ["--user-data-dir=C:/Users/%A_UserName%/AppData/Local/Google/Chrome/User Data"],
grafik.png
grafik.png (24.04 KiB) Viewed 4097 times
another idea?

Thank you

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 25 Apr 2022, 03:31

Milchmann wrote:
25 Apr 2022, 03:12
Does not work :

Code: Select all

 "args": ["--user-data-dir=C:/Users/%A_UserName%/AppData/Local/Google/Chrome/User Data"],
grafik.png
another idea?

Thank you
.error says "cannot create default profile directory" hmmm
I haven't tried created session with my default chrome profile I can't say why webdriver trying to create directory instead reading it, or may be webdriver might not found profile directory,

ok I just found please confirm profile path using url chrome://version/
if should be

Code: Select all

"args": ["--user-data-dir=C:\Users\" a_username "\AppData\Local\Google\Chrome\User Data\Profile"]
"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 » 25 Apr 2022, 07:29

ok I just found please confirm profile path using url chrome://version/
if should be

Code: Select all

"args": ["--user-data-dir=C:\Users\" a_username "\AppData\Local\Google\Chrome\User Data\Profile"]
[/quote]


Thank you works,
.error says "cannot create default profile directory" hmmm
Do you have an example. I don`t understand......

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

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Xeo786 » 25 Apr 2022, 08:02

Milchmann wrote:
25 Apr 2022, 07:29
Do you have an example. I don`t understand......
paste following url into address bar of chrome and check correct profile path
chrome://version/
"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)”