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: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.6.3 (no selenium/websocket)

Post by Xeo786 » 13 Jul 2022, 01:24

pAnDeLa wrote:
13 Jul 2022, 01:12
pAnDeLa wrote:
12 Jul 2022, 14:47
I see there are functions for dragging and dropping web elements, but is it possible to simulate dropping a file onto a droppable webpage element or file input element, via Rufaydium?
You can check web-driver actions or Rufaydium's Session.Actions() actually I am planning to write action class to make this stuff easy.
Oh nice thx, those are great resources! And I should've read the Rufaydium docs more though lol,
drag and drop simulation/substitution can also be done with:

Code: Select all

;simulate drag and drop file via file input element
filelocation := "C:\Users\username\Pictures\image.png" ;set file path
UploadFile := Page.querySelectorAll(".chatEntry input[name=fileupload")[0] ;select file input element
UploadFile.Sendkey(StrReplace(filelocation,"\","/")) ;if Element is input element then file location can be set using SendKey()
Yeah, I know that. Some web pages have draggable elements I thought you were asking for that :D
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

pAnDeLa
Posts: 6
Joined: 02 Apr 2017, 03:33

Re: Rufaydium WebDriver 1.6.3 (no selenium/websocket)

Post by pAnDeLa » 13 Jul 2022, 07:00

pAnDeLa wrote:
06 Jul 2022, 20:49

Thanks for getting back, I did a lot of digging and was able to find a flag that actually logs js console messages!
That flag being --webview-log-js-console-messages. While the method you posted into getting the browser log is great and yields far more detailed information, I have a quick solution as well :D The chrome_debug.log file generated by chrome is deleted every time you reopen chrome too. If I recall you must use the Default or current Chrome Profile in Rufaydium as well.

Here's a working example of js callbacks in Rufaydium & Chrome, thanks again for this amazing library 8-)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Include Rufaydium.ahk
#SingleInstance,Force


if (A_Args.Length() = 0) {
	Run, "C:\Program Files\AutoHotkey\AutoHotkeyU64.exe" %A_ScriptFullPath% 1
	ExitApp
}


Chrome_Log := new CLogTailer("C:\Users\uername\AppData\Local\Google\Chrome\User Data\chrome_debug.log", Func("ReadLog"))
ReadLog(Console_Output){
	;ToolTip % "New line added @ " A_TickCount ": " text
	if RegExMatch(Console_Output,"hello world!") { 
		msgbox, Houston we have lift off!
		gosub, DoStuff
	}
}

/*
	Load "chromedriver.exe" from "A_ScriptDir"
	In case Driver is not yet available, it will Download "chromedriver.exe" into "A_ScriptDir"
	before starting the Driver.
*/

ChromeInst := new Rufaydium("chromedriver.exe", "--port=9515")
ChromeInst.capabilities.setUserProfile("Default") ;use Default chrome profile
ChromeInst.capabilities.addArg(" --enable-logging ") ;enable chrome_debug.log file
ChromeInst.capabilities.addArg(" --v=0 ") ;needed for above logging flag to work
ChromeInst.capabilities.addArg(" --webview-log-js-console-messages ") ;this undocumented flag is the peace de la resistance we need for js/console to ahk callbacks to work

/*
	Create new session if WebBrowser Version Matches the Webdriver Version.
	It will ask to download the compatible WebDriver if not present.
*/

Page := ChromeInst.NewSession()
;Page := ChromeInst.NewSession("C:\Program Files\Google\Chrome\Application\chrome.exe")
;Page.CDP.call("Console.enable") ;not needed in this case
Page.Navigate("https://www.autohotkey.com/docs/AutoHotkey.htm") ; navigate to url
sleep, 1000

gosub, InjectJS
return

DoStuff:
Settings := Page.getElementsByClassName("settings")[0] ;open settings page
Settings.Click()
msgbox, We did stuff!
return


;https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
;https://www.autohotkey.com/boards/viewtopic.php?style=17&p=306235#p306235
InjectJS:
JS_MutationObserver =
(
function init() {
  if (window.MutationObserver) {
    startMutationObserver();
  } else {
    startMutationEvents();
  }
}

function startMutationObserver() {
  // target node to be observed
  var target = document.querySelector('body');
  // mutation observer config object with the listeners configuration
  var config = listenOnlyAttributeChanges();

  // mutation observer instantiation
  var mutationObs = new MutationObserver(callbackAttributeChange);

  // observe initialization
  mutationObs.observe(target, config);
}

function listenOnlyAttributeChanges() {
  return {
    attributes: true,
    childList: true,
    subtree: true
  };
}

function callbackAttributeChange(mutations, mutationObs) {
  for (var i = 0, length = mutations.length; i < length; i++) {
    var mutation = mutations[i];
    if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
      var target = mutation.target;
      console.log(target.id + target.style.display);
      console.log("---" + target.id + target.class);
	 
	 //test
	 console.log("hello world!");
    }
  }
}

var addedNodes = 0;
var colorpage = false;
init();
)

;Inject Mutation Observer
Page.CDP.Evaluate(JS_MutationObserver)
return


F12::
ChromeInst.QuitAllSessions() ; close all session 
ChromeInst.Driver.Exit() ; then exits driver
Process,Close,chromedriver.exe ;force closer driver
ExitApp


;https://www.autohotkey.com/boards/viewtopic.php?t=47894#p215692
class CLogTailer {
	__New(logfile, callback){
		this.file := FileOpen(logfile, "r-d")
		this.callback := callback
		; Move seek to end of file
		this.file.Seek(0, 2)
		fn := this.WatchLog.Bind(this)
		SetTimer, % fn, 100
	}
	
	WatchLog(){
		Loop {
			p := this.file.Tell()
			l := this.file.Length
			line := this.file.ReadLine(), "`r`n"
			len := StrLen(line)
			if (len){
				RegExMatch(line, "[\r\n]+", matches)
				if (line == matches)
					continue
				this.callback.Call(Trim(line, "`r`n"))
			}
		} until (p == l)
	}
}
If you want to do this in headless mode, you'll need the flags:

Code: Select all

ChromeInst.capabilities.addArg(" --window-size=1920,1080 ")
ChromeInst.capabilities.addArg(" --start-maximized ")
ChromeInst.capabilities.addArg(" --headless ") 
ChromeInst.capabilities.addArg(" --ignore-certificate-errors ")
ChromeInst.capabilities.addArg(" --allow-running-insecure-content ") ;needed for headless
ChromeInst.capabilities.addArg(" --disable-gpu ")
ChromeInst.capabilities.addArg(" --user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36 ")
Its also worth noting that when I used headless mode, the chrome_debug.txt normally located in
C:\Users\username\AppData\Local\Google\Chrome\User Data was now being generated in
C:\Users\username\AppData\Local\Google\Chrome\User Data\Default instead.
Not sure if that is intended behavior or an error on my part, but hopefully that knowledge will save some trouble :p
So yea, be sure to point your CLogTailer() function to the proper chrome_debug.txt log file path in headless mode

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

Re: Rufaydium WebDriver 1.6.3 (no selenium/websocket)

Post by Xeo786 » 13 Jul 2022, 07:48

pAnDeLa wrote:
13 Jul 2022, 07:00
pAnDeLa wrote:
06 Jul 2022, 20:49

Thanks for getting back, I did a lot of digging and was able to find a flag that actually logs js console messages!
That flag being --webview-log-js-console-messages. While the method you posted into getting the browser log is great and yields far more detailed information, I have a quick solution as well :D The chrome_debug.log file generated by chrome is deleted every time you reopen chrome too. If I recall you must use the Default or current Chrome Profile in Rufaydium as well.

Here's a working example of js callbacks in Rufaydium & Chrome, thanks again for this amazing library 8-)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Include Rufaydium.ahk
#SingleInstance,Force


if (A_Args.Length() = 0) {
	Run, "C:\Program Files\AutoHotkey\AutoHotkeyU64.exe" %A_ScriptFullPath% 1
	ExitApp
}


Chrome_Log := new CLogTailer("C:\Users\uername\AppData\Local\Google\Chrome\User Data\chrome_debug.log", Func("ReadLog"))
ReadLog(Console_Output){
	;ToolTip % "New line added @ " A_TickCount ": " text
	if RegExMatch(Console_Output,"hello world!") { 
		msgbox, Houston we have lift off!
		gosub, DoStuff
	}
}

/*
	Load "chromedriver.exe" from "A_ScriptDir"
	In case Driver is not yet available, it will Download "chromedriver.exe" into "A_ScriptDir"
	before starting the Driver.
*/

ChromeInst := new Rufaydium("chromedriver.exe", "--port=9515")
ChromeInst.capabilities.setUserProfile("Default") ;use Default chrome profile
ChromeInst.capabilities.addArg(" --enable-logging ") ;enable chrome_debug.log file
ChromeInst.capabilities.addArg(" --v=0 ") ;needed for above logging flag to work
ChromeInst.capabilities.addArg(" --webview-log-js-console-messages ") ;this undocumented flag is the peace de la resistance we need for js/console to ahk callbacks to work

/*
	Create new session if WebBrowser Version Matches the Webdriver Version.
	It will ask to download the compatible WebDriver if not present.
*/

Page := ChromeInst.NewSession()
;Page := ChromeInst.NewSession("C:\Program Files\Google\Chrome\Application\chrome.exe")
;Page.CDP.call("Console.enable") ;not needed in this case
Page.Navigate("https://www.autohotkey.com/docs/AutoHotkey.htm") ; navigate to url
sleep, 1000

gosub, InjectJS
return

DoStuff:
Settings := Page.getElementsByClassName("settings")[0] ;open settings page
Settings.Click()
msgbox, We did stuff!
return


;https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
;https://www.autohotkey.com/boards/viewtopic.php?style=17&p=306235#p306235
InjectJS:
JS_MutationObserver =
(
function init() {
  if (window.MutationObserver) {
    startMutationObserver();
  } else {
    startMutationEvents();
  }
}

function startMutationObserver() {
  // target node to be observed
  var target = document.querySelector('body');
  // mutation observer config object with the listeners configuration
  var config = listenOnlyAttributeChanges();

  // mutation observer instantiation
  var mutationObs = new MutationObserver(callbackAttributeChange);

  // observe initialization
  mutationObs.observe(target, config);
}

function listenOnlyAttributeChanges() {
  return {
    attributes: true,
    childList: true,
    subtree: true
  };
}

function callbackAttributeChange(mutations, mutationObs) {
  for (var i = 0, length = mutations.length; i < length; i++) {
    var mutation = mutations[i];
    if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
      var target = mutation.target;
      console.log(target.id + target.style.display);
      console.log("---" + target.id + target.class);
	 
	 //test
	 console.log("hello world!");
    }
  }
}

var addedNodes = 0;
var colorpage = false;
init();
)

;Inject Mutation Observer
Page.CDP.Evaluate(JS_MutationObserver)
return


F12::
ChromeInst.QuitAllSessions() ; close all session 
ChromeInst.Driver.Exit() ; then exits driver
Process,Close,chromedriver.exe ;force closer driver
ExitApp


;https://www.autohotkey.com/boards/viewtopic.php?t=47894#p215692
class CLogTailer {
	__New(logfile, callback){
		this.file := FileOpen(logfile, "r-d")
		this.callback := callback
		; Move seek to end of file
		this.file.Seek(0, 2)
		fn := this.WatchLog.Bind(this)
		SetTimer, % fn, 100
	}
	
	WatchLog(){
		Loop {
			p := this.file.Tell()
			l := this.file.Length
			line := this.file.ReadLine(), "`r`n"
			len := StrLen(line)
			if (len){
				RegExMatch(line, "[\r\n]+", matches)
				if (line == matches)
					continue
				this.callback.Call(Trim(line, "`r`n"))
			}
		} until (p == l)
	}
}
If you want to do this in headless mode, you'll need the flags:

Code: Select all

ChromeInst.capabilities.addArg(" --window-size=1920,1080 ")
ChromeInst.capabilities.addArg(" --start-maximized ")
ChromeInst.capabilities.addArg(" --headless ") 
ChromeInst.capabilities.addArg(" --ignore-certificate-errors ")
ChromeInst.capabilities.addArg(" --allow-running-insecure-content ") ;needed for headless
ChromeInst.capabilities.addArg(" --disable-gpu ")
ChromeInst.capabilities.addArg(" --user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36 ")
Its also worth noting that when I used headless mode, the chrome_debug.txt normally located in
C:\Users\username\AppData\Local\Google\Chrome\User Data was now being generated in
C:\Users\username\AppData\Local\Google\Chrome\User Data\Default instead.
Not sure if that is intended behavior or an error on my part, but hopefully that knowledge will save some trouble :p
So yea, be sure to point your CLogTailer() function to the proper chrome_debug.txt log file path in headless mode
thanks awsome ...!
btw no spaces on both ends are needed for commandline swicths/args

Code: Select all

ChromeInst.capabilities.addArg("--disable-gpu") ; no space needed
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.6.3 (no selenium/websocket)

Post by Xeo786 » 19 Jul 2022, 08:29

Just Implemented Action Class, did following test

Code: Select all

#Include, %A_ScriptDir%\..\Rufaydium-Webdriver
#include Rufaydium.ahk 
goto, TestKeyboard
return

clickTest:
URL := "https://quickdraw.withgoogle.com"
page := GetRufaydium(URL) ; run/access  chrome  browser

MouseEvent := new mouse()
;MouseEvent.click(0, 400, 400)
;MouseEvent.click(1, 200, 300)

MouseEvent.press()
MouseEvent.move(288,258,10)
MouseEvent.release()
MouseEvent.press()
MouseEvent.move(391,181,10)
MouseEvent.release()
MouseEvent.press()
MouseEvent.move(493,258,10)
MouseEvent.release()
MouseEvent.press()
MouseEvent.move(454,358,10)
MouseEvent.release()
MouseEvent.press()
MouseEvent.move(328,358,10)
MouseEvent.release()
MouseEvent.press()
MouseEvent.move(288,258,10)
MouseEvent.release()
MouseEvent.press()
MouseEvent.release()
msgbox, move drawing window and click ok to draw
x := page.actions(MouseEvent)
return


ScrollTest:
URL :=  "https://www.autohotkey.com/boards/"
page := GetRufaydium(URL) ; run/access  chrome  browser
WheelEvent := new Scroll()
return

down::
page.scrollDown()
return

up::
page.scrollup()
return

TestKeyboard:
URL :=  "https://www.autohotkey.com/boards/"
page := GetRufaydium(URL) ; run/access  chrome  browser
e := Page.querySelector("#keywords")
e.focus()
page.sendkey("aBcd")
page.sendkey("xyZ")
return
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

User avatar
hotcheesesoup
Posts: 34
Joined: 08 May 2022, 01:41

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by hotcheesesoup » 19 Jul 2022, 09:21

@Xeo786
Very cool! I'll have to check this out. The site we use at work has hidden fields that require injecting a JSON object, so it's really a pain to automate them. Maybe sending keystrokes instead would get around that limitation.

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 19 Jul 2022, 09:42

hotcheesesoup wrote:
19 Jul 2022, 09:21
@Xeo786
Very cool! I'll have to check this out. The site we use at work has hidden fields that require injecting a JSON object, so it's really a pain to automate them. Maybe sending keystrokes instead would get around that limitation.
It was complicated to create case-sensitive/proper/overcomplicated JSON object. It took to so much time to find the correct JSON parameters/formations.
Now we have Action.ahk to simplifies JSON objects creation.
Spoiler
You can take multiple events i.e.

Code: Select all

Page.Actions(MouseEvent, KeyboardEvent, ScrollEvent, Mouse2Event) ; can add more / will be triggered from left to right
I am curious what kind of JSON object you are sending, if you have any suggestion feel free.

Edit: fixed mistake in code
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

User avatar
hotcheesesoup
Posts: 34
Joined: 08 May 2022, 01:41

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by hotcheesesoup » 19 Jul 2022, 11:14

@Xeo786
Here's an example of the JSON payload I'm injecting into a hidden "ClientState" field. Typically the value of the hidden field doesn't even show up until you focus the Input field and physically type text into it.

Code: Select all

				
hiddenValue = {"logEntries":[],"value":"15","text":"Pending","enabled":true,"checkedIndices":[],"checkedItemsTextOverflows":false}
Session.CDP.Evaluate("document.getElementById('ctl00_Detail_ApplicationStatus_Input').value = 'Pending'")
Session.CDP.Evaluate("document.getElementById('ctl00_Detail_ApplicationStatus_ClientState').value = '" hiddenValue "'")
This works for most of the hidden fields, but sometimes it is easier to just focus the Input field and send simulated keystrokes then hit Tab a few times to make it trigger the hidden ClientState value.

The old version of our program didn't do any data validation until you submitted, and didn't require the JSON payload, so you could edit fields without even being in Edit mode, etc.

I will give the new stuff a shot when I have a chance and report back!

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 20 Jul 2022, 02:03

hotcheesesoup wrote:
19 Jul 2022, 11:14
@Xeo786
Here's an example of the JSON payload I'm injecting into a hidden "ClientState" field. Typically the value of the hidden field doesn't even show up until you focus on the Input field and physically type text into it.

Code: Select all

				
hiddenValue = {"logEntries":[],"value":"15","text":"Pending","enabled":true,"checkedIndices":[],"checkedItemsTextOverflows":false}
Session.CDP.Evaluate("document.getElementById('ctl00_Detail_ApplicationStatus_Input').value = 'Pending'")
Session.CDP.Evaluate("document.getElementById('ctl00_Detail_ApplicationStatus_ClientState').value = '" hiddenValue "'")
This works for most of the hidden fields, but sometimes it is easier to just focus the Input field and send simulated keystrokes then hit Tab a few times to make it trigger the hidden ClientState value.

The old version of our program didn't do any data validation until you submitted and didn't require the JSON payload, so you could edit fields without even being in Edit mode, etc.

I will give the new stuff a shot when I have a chance and report back!
No need to use CDP, You can use page.ExecuteSync(JS) to execute any JS and Element.execute(JS) evaluate JS on page but you can access element pointer as arguments[0] please look into WDElements.ahk for examples, now WDElements class can have much control over elements, i.e. you can use .focus(), change .innetText, .id, .class, .Title, .Name, .innerHTML, .outerHTML and any attribute/ property using .Execute()

Can you please try these and share the results

Code: Select all

hiddenValue = {"logEntries":[],"value":"15","text":"Pending","enabled":true,"checkedIndices":[],"checkedItemsTextOverflows":false}
e := Page.getElementById("ctl00_Detail_ApplicationStatus_Input")
e.focus()

; tests
e.value := hiddenValue ; try setting simply
e.value := json.load(hiddenValue) ; try setting json Object you can also do/use ":=" >> e.value := {"logEntries".....
e.execute("arguments[0].value = '" hiddenValue "'") ; execute JS on element and element pointer will be 'arguments[0]'
; no need for CDP rufaydium Basic manipulate element 
Page.ExecuteSync("document.getElementById('ctl00_Detail_ApplicationStatus_ClientState').value = '" hiddenValue "'")
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

pAnDeLa
Posts: 6
Joined: 02 Apr 2017, 03:33

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by pAnDeLa » 20 Jul 2022, 02:18

Is this possible in Rufaydium too?
I'm able to connect to an already opened Chromium browser via Chrome.ahk using this simple script, but am uncertain how to do the same in Rufaydium

Code: Select all

#Include Chrome.ahk ; https://github.com/G33kDude/Chrome.ahk
Chrome := {"base": Chrome, "DebugPort": 8080} 
TabInst := Chrome.GetPage()
TabInst.Evaluate("alert('Hello World!');")

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 20 Jul 2022, 08:17

pAnDeLa wrote:
20 Jul 2022, 02:18
Is this possible in Rufaydium too?
I'm able to connect to an already opened Chromium browser via Chrome.ahk using this simple script, but am uncertain how to do the same in Rufaydium

Code: Select all

#Include Chrome.ahk ; https://github.com/G33kDude/Chrome.ahk
Chrome := {"base": Chrome, "DebugPort": 8080} 
TabInst := Chrome.GetPage()
TabInst.Evaluate("alert('Hello World!');")
You can Access Browser Session created using Webdriver only, just like Chrome.ahk, which needs chrome to run in debugging mode
Following function is a good example for getting page once created using webdriver

Code: Select all

Page := GetRufaydium("https://github.com/G33kDude/Chrome.ahk")
Msgbox, % Page.Title "`n" Page.URL  "`n`n run this code again to acces same page `n`n Press f12 to quit Page and driver"
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

adrian_9832
Posts: 26
Joined: 23 Dec 2018, 00:40

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by adrian_9832 » 21 Jul 2022, 07:55

Can I hide the chrome browser like run in background

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 21 Jul 2022, 08:28

adrian_9832 wrote:
21 Jul 2022, 07:55
Can I hide the chrome browser like run in background
you need to run chrome in headlessmode

example

Code: Select all

#include Rufaydium.ahk 
Chrome := new Rufaydium() 
Chrome.Capabilities.HeadlessMode := true
Page := Chrome.NewSession()
Page.url := "https://www.autohotkey.com/boards"

Msgbox, % Page.Title "`n" Page.URL  "`n`n Press f12 to quit Page and driver"
return
f12::
Chrome := new Rufaydium() 
Chrome.QuitAllSessions() ; close all session 
Chrome.Driver.Exit() ; then exits driver
msgbox, all session closed and Driver Exitted
return
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

noslined
Posts: 6
Joined: 05 Apr 2020, 16:34

Re: Rufaydium WebDriver 1.6.3 (no selenium/websocket)

Post by noslined » 22 Jul 2022, 19:20

I didn't get this code to work:

Code: Select all

#Include, %A_ScriptDir%\..\Rufaydium-Webdriver
#include Rufaydium.ahk 

URL :=  "https://www.autohotkey.com/boards/"
page := Navigate(URL) ; run/access  chrome  browser
WheelEvent := new Scroll()
page.scrollDown()
return
Also didn't understood about that GetRufaydium, is it a new function or just an example? Couldn't find it.

I also would love if you give me an example to Send a key to the page, not an element, like an Arrow Down, PageUp, etc. I'm not sure if is possible with this new Action Class, tried following your example, but also didn't work.

Thank you! Your library is amazing and is helping a lot everyday

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

Re: Rufaydium WebDriver 1.6.3 (no selenium/websocket)

Post by Xeo786 » 23 Jul 2022, 01:19

noslined wrote:
22 Jul 2022, 19:20
I didn't get this code to work:

Code: Select all

#Include, %A_ScriptDir%\..\Rufaydium-Webdriver
#include Rufaydium.ahk 

URL :=  "https://www.autohotkey.com/boards/"
page := Navigate(URL) ; run/access  chrome  browser
WheelEvent := new Scroll()
page.scrollDown()
return
Also didn't understood about that GetRufaydium, is it a new function or just an example? Couldn't find it.

I also would love if you give me an example to Send a key to the page, not an element, like an Arrow Down, PageUp, etc. I'm not sure if is possible with this new Action Class, tried following your example, but also didn't work.

Thank you! Your library is amazing and is helping a lot everyday
Please Read Documentation how to use Rufaydium

1) Rufaydium uses webdriver, it can download/load various webdrive by creating New Rufaydium("DriverName") instance, reference

1.1) it is optional, you can use capabilities to invoke specific browser options like incognito mode, etc.

2) After Creating New Rufaydium instance you need to Run Browser/create Page, by using NewSession() Method,

2.2 You can also access already create Rufaydium session by using various methods see this

Now you are ready to automate Browser using various Session methods,

Code: Select all

#include Rufaydium.ahk 
Chrome := new Rufaydium()  ; first you need to load driver here we are loading Chrome driver 
Page := Chrome.NewSession() ; then we need to create session, Session will open chrome page 
Page.url := "https://www.autohotkey.com/boards" ; same as Page.Navigate(URL)  this is how we navigate to page script will wait till page fully loaded
page.scrollDown()  ; then we scroll down ..... 

;you can also use scroll event which actually doing what 'page.scrollDown()'  just did 
WheelEvent := new Scroll() 
WheelEvent.ScrollDown(s)
Page.Actions(WheelEvent)
return


f12::
Chrome := new Rufaydium() 
Chrome.QuitAllSessions() ; close all session 
Chrome.Driver.Exit() ; then exits driver
msgbox, all session closed and Driver Exitted
return
Last edited by Xeo786 on 27 Jul 2022, 00:36, edited 1 time in total.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

1apsalman1
Posts: 6
Joined: 12 Apr 2022, 12:57

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by 1apsalman1 » 25 Jul 2022, 10:16

hello. Is there a way to control the chrome browser that is already turned on? I wrote the script like this, but it doesn't get the Title.

Code: Select all

Chrome := new Rufaydium("chromedriver.exe")
Page := Chrome.getSessionByURL("https://www.autohotkey.com/boards/viewtopic.php?f=6&t=102616&hilit=rufaydium")
Msgbox, % Page.Title

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by ahk7 » 25 Jul 2022, 14:00

Try

Code: Select all

url:="https://www.autohotkey.com/boards/viewtopic.php?f=6&t=102616&hilit=rufaydium"

Browser:=new Rufaydium()
Page:=Browser.NewSession()
Page.Navigate(url)
Session:=Browser.getSessionByUrl(url)
Msgbox, % Session.Title

1apsalman1
Posts: 6
Joined: 12 Apr 2022, 12:57

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by 1apsalman1 » 26 Jul 2022, 15:57

That script opens new browser, is there any way to control which browser is already openned?

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by Xeo786 » 27 Jul 2022, 00:33

1apsalman1 wrote:
26 Jul 2022, 15:57
That script opens new browser, is there any way to control which browser is already openned?
No, you can't. Normally running Browser is not a Webdriver Session.
"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 » 27 Jul 2022, 13:09

My apologies, but I've back with same problem.
What I have:
* Chrome 103, updating showing the last version. Does 64-bit fine?
* Win11, 64 bit
* Manually downloaded and putted cromedriver for chrome 103. I've put it to \chromedriver_win32\file.ahk folder

Whats wrong:
If I use

Code: Select all

Chrome := new Rufaydium() ; default will load driver
Page := Chrome.NewSession()
Page.Navigate("https://www.autohotkey.com/")
return

f12::
Chrome.QuitAllSessions() ; close all session 
Chrome.Driver.Exit() ; then exits driver
return
- no any visible effect, but I see an activity in processes dispetch

Using this:

Code: Select all

#include Rufaydium.ahk 
Chrome := new Rufaydium()  ; first you need to load driver here we are loading Chrome driver 
Page := Chrome.NewSession() ; then we need to create session, Session will open chrome page 
Page.url := "https://www.autohotkey.com/boards" ; same as Page.Navigate(URL)  this is how we navigate to page script will wait till page fully loaded
page.scrollDown()  ; then we scroll down ..... 

;you can also use scroll event which actually doing what 'page.scrollDown()'  just did 
WheelEvent := new Scroll() 
WheelEvent.ScrollDown(s)
Page.Actions(WheelEvent)
return

f12::
Chrome := new Rufaydium() 
Chrome.QuitAllSessions() ; close all session 
Chrome.Driver.Exit() ; then exits driver
msgbox, all session closed and Driver Exitted
return
...I see an error as in attached image.

What I do wrong?
Attachments
Screenshot_25.png
Screenshot_25.png (24.49 KiB) Viewed 3829 times

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

Re: Rufaydium WebDriver 1.7.0 (no selenium/websocket)

Post by murataygun » 27 Jul 2022, 13:23

Can i wait user to click a specified button and than continue?

Post Reply

Return to “Scripts and Functions (v1)”