Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post your working scripts, libraries and tools for AHK v1.1 and older
Milchmann
Posts: 112
Joined: 05 Nov 2016, 08:50

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Milchmann » 02 Jun 2022, 00:52

Try look into html if element HTML has Value attribute then it should bring it to you. if there is no the attribute.
it has, since I get a value with :

Code: Select all

Page.CDP.Evaluate("document.querySelector('#keywords').value;").value
But not with:

Code: Select all

msgbox %  "`nkeywords value from Basic : " Page.QuerySelector("#keywords").value
. "`nkeywords value from CDP: " Page.cdp.QuerySelector("#keywords").value
Thanks

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 02 Jun 2022, 02:14

Both methods are not same
Milchmann wrote:
02 Jun 2022, 00:52

Code: Select all

Page.CDP.Evaluate("document.querySelector('#keywords').value;").value
above method get Evaluate JS and return with calculated result,
Milchmann wrote:
02 Jun 2022, 00:52

Code: Select all

msgbox %  "`nkeywords value from Basic : " Page.QuerySelector("#keywords").value
. "`nkeywords value from CDP: " Page.cdp.QuerySelector("#keywords").value
above methods just returns 'value' which should be Property / attribute of that element's HTML.

Just look at following Image, line 1 returns line 2 with HTML it has 'name', 'id', 'type',...... but value is empty same as value=""
but line 3 resulting line 4 which actually returns with value,
image.png
image.png (49.17 KiB) Viewed 3567 times
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Milchmann » 02 Jun 2022, 03:56

ok thanks, so i can only query most value values with

Code: Select all

Page.CDP.Evaluate("document.querySelector('#keywords').value;").value
evaluate?
Not with Basic and also not with cdp?

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 02 Jun 2022, 04:41

Milchmann wrote:
02 Jun 2022, 03:56
ok thanks, so i can only query most value values with

Code: Select all

Page.CDP.Evaluate("document.querySelector('#keywords').value;").value
evaluate?
Not with Basic and also not with cdp?
yah It depends on Page and HTML and how webpage is designed, sometime we need to evaluate js most of the time getting value is simple
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Milchmann » 03 Jun 2022, 04:05

Hi
is it possible to save the values with .cdp. get?
Element.Name() ; will return tagname
Element.Rect() ; will return position and size
Element.Size() ; will return Size
Element.Location() ; will return position
Element.LocationInView() ; will return position in view
.

Code: Select all

sessionelement := driver.QuerySelector("#keywords").Rect()  ; works 
MsgBox %  json.dump(sessionelement)

sessionelement := driver.cdp.QuerySelector("#keywords").Rect() ; error
MsgBox % json.dump(sessionelement)

The background is that I have formed complex objects with .cdp. and then need these values.


Thanks

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 03 Jun 2022, 04:38

Milchmann wrote:
03 Jun 2022, 04:05
is it possible to save the values with .cdp. get?
with basic element we get Rect location and Size and with CDP we can get whole BoxModel by using CDP_element.getBoxModel() which is using DOM.getBoxModel

Code: Select all

BoxModel := Session.CDP.querySelector("#keywords").getBoxModel()
MsgBox % json.dump(BoxModel,1)
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Nivol
Posts: 6
Joined: 31 Jul 2021, 09:54

Re: Rufaydium WebDriver (no selenium/websocket)

Post by Nivol » 05 Jun 2022, 21:16

ahk7 wrote:
27 Apr 2022, 12:30
thalesduarte wrote:
27 Apr 2022, 11:40
Can you share an example script by filling out a form on the web and clicking the SUBMIT button?
This visits the ahk forum, searches and then closes the script after the MsgBox, probably as short as it can be as an example. Here I use .SendKey() to press enter to start the search, but .click() on the button element in other cases might be more useful.

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)

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

element[1].value:="Rufaydium"
element[1].SendKey(key.enter)

MsgBox, Now closing script, chrome and webdriver

GS:=""
Page := ""

Chrome.QuitAllSessions()
driver.exit()

ExitApp

Hello,

I'm migrating over from IE and i'm having trouble selecting elements in order to click() them or put a value := into fields.

Essentially, things like navigating and maximizing webpages works, but working with elements do not.

I've tried something similar to the above example, everything works except putting the value "rufaydium" into the field and sending enter on that webpage.

Code: Select all

#SingleInstance, force
#Include Rufaydium.ahk

Chrome := new Rufaydium("chromedriver.exe")

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

GS := Chrome.getSessionByUrl(url)

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

element[1].value:="Rufaydium"
element[1].SendKey(key.enter)

MsgBox, Now closing script, chrome and webdriver

GS:=""
Page := ""

Chrome.QuitAllSessions()
driver.exit()

ExitApp


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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 06 Jun 2022, 01:25

There have been some changes to Rufaydium so the same script should now be

Code: Select all

#SingleInstance, force
#Include Rufaydium.ahk

Chrome := new Rufaydium("chromedriver.exe")

url:="https://www.autohotkey.com/boards/" ; was missing

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

GS := Chrome.getSessionByUrl(url)

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

element[0].value:="Rufaydium" ; now starts at 0, not 1
element[0].SendKey(key.enter)

MsgBox, Now closing script, chrome and webdriver

GS:=""
Page := ""

Chrome.QuitAllSessions()
driver.exit()

ExitApp

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 06 Jun 2022, 03:25

ahk7 wrote:
06 Jun 2022, 01:25
There have been some changes to Rufaydium so the same script should now be

Code: Select all

#SingleInstance, force
#Include Rufaydium.ahk

Chrome := new Rufaydium("chromedriver.exe")

url:="https://www.autohotkey.com/boards/" ; was missing

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

GS := Chrome.getSessionByUrl(url)

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

element[0].value:="Rufaydium" ; now starts at 0, not 1
element[0].SendKey(key.enter)

MsgBox, Now closing script, chrome and webdriver

GS:=""
Page := ""

Chrome.QuitAllSessions()
driver.exit()

ExitApp
AHK array starts from 1 and JS starts from zero, since Rufaydium mimics the DOM JS syntax very I was suggested to follow JS syntax properly,
i.e. if we just change Session pointer to Document we do not event have to change the code from chrome console at all,

Code: Select all

document := Chrome.NewSession()
document.querySelectorAll("*")[94].click()
image.png
image.png (17.2 KiB) Viewed 3102 times
I wrote Rufaydium to start from 1, I liked the Simplicity of AHK array, and I usually use For loop in my code, there is a way to provide Element Object Start mode, so user can choose what Array type he is willing to use. something like

Code: Select all

Chrome := New Rufaydium()
;Chrome.ElementArrayMode := "JS"  or "AHK"  or  Chrome.ElementStartMode := 0 or 1
if you have better suggestion please do tell me. :D
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 06 Jun 2022, 03:53

It's fine the way it is I think, it is just an example of why having the central documentation like you have now on Github is useful.
The question was about an older example script that doesn't work with the latest version.

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

Re: Rufaydium WebDriver 1.6.0 (no selenium/websocket)

Post by docterry » 09 Jun 2022, 01:03

Xeo786 wrote:
31 May 2022, 02:58
docterry wrote:
31 May 2022, 00:11
I have an AHK script which downloads recent files from a webpage list using session.element[0].click(). It then renames that file and copies to a share folder.
You can use following code, to change default download path at any point after creating session. Make sure to use / instead \ for download path

Code: Select all

;here Page is session 
Page.CDP.Call("Browser.setDownloadBehavior", { "behavior" : "allow", "downloadPath" : "D:/newpath"}) 
for edge you can simply use MsEdgedriver and setuserprofile() method from Session.Capabilities look into readme.md on git
Great! I was able to change the downloadPath just as you described.

When I manually click on the button, the file downloads properly to the new path.

However, when I use session.element[0].click(), it downloads to the default path. Any idea why it would behave like this?

Nivol
Posts: 6
Joined: 31 Jul 2021, 09:54

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Nivol » 10 Jun 2022, 09:00

@Xeo786
Thank you, changing the session pointer to "document" was a great tip.

@ahk7
Thanks to you as well, it works well.

I am wondering if you can help me with another simple thing regarding clicking a button (it links to another webpage) specifically using getElementById.

The element in Chrome (cut it off at href ,sorry can't share the webpage):
<a id="205123" class="s-receiveButton rollover button " href......

When I type the following into the Chrome Console (or using is with AHK with IE) the button works:
Console:

Code: Select all

document.getElementById("205123").click()
AHK with IE (wb is the pointer):

Code: Select all

wb.document.getElementById("205123").click()
However I am having difficulty making it work with Rufaydium:

Code: Select all

#SingleInstance, Force
#Include Rufaydium.ahk

Chrome := new Rufaydium("chromedriver.exe")
document := Chrome.NewSession()
return

;I then navigate to the webpage the element is on and press the hotkey below

`::
Element := document.getElementById("205123")
Element.click()
return
I'm, curious where I am going wrong here.

If it's unwieldly dealing with my example, could an example be demonstrated using another webpage so I can learn from it. Thanks.

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Xeo786 » 10 Jun 2022, 11:14

Nivol wrote:
10 Jun 2022, 09:00
@Xeo786
Thank you, changing the session pointer to "document" was a great tip.

@ahk7
Thanks to you as well, it works well.

I am wondering if you can help me with another simple thing regarding clicking a button (it links to another webpage) specifically using getElementById.

The element in Chrome (cut it off at href ,sorry can't share the webpage):
<a id="205123" class="s-receiveButton rollover button " href......

When I type the following into the Chrome Console (or using is with AHK with IE) the button works:
Console:

Code: Select all

document.getElementById("205123").click()
AHK with IE (wb is the pointer):

Code: Select all

wb.document.getElementById("205123").click()
However I am having difficulty making it work with Rufaydium:

Code: Select all

#SingleInstance, Force
#Include Rufaydium.ahk

Chrome := new Rufaydium("chromedriver.exe")
document := Chrome.NewSession()
return

;I then navigate to the webpage the element is on and press the hotkey below

`::
Element := document.getElementById("205123")
Element.click()
return
I'm, curious where I am going wrong here.

If it's unwieldly dealing with my example, could an example be demonstrated using another webpage so I can learn from it. Thanks.
if you have navigated to webpage and loading if finished then you code should work, you can check for error too

Code: Select all

Element := document.getElementById("205123")
if Element.error
	msgbox, % Element.error
c := Element.click()
if c.error
	msgbox, % c.error
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.6.0 (no selenium/websocket)

Post by Xeo786 » 10 Jun 2022, 11:15

docterry wrote:
09 Jun 2022, 01:03
However, when I use session.element[0].click(), it downloads to the default path. Any idea why it would behave like this?
not sure about it will look into that later
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 10 Jun 2022, 11:21

I find that not all methods work all the time for whatever reason, so I try byId byName and Xpath - often one them will work (although in principle they all should in most cases but whatever gets the job done)

You could try

Code: Select all

Element := document.getElementsbyXpath("//*[@id=""205123""]")
Element[0].click() ; Remember it returns an object so use [number].something

Nivol
Posts: 6
Joined: 31 Jul 2021, 09:54

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Nivol » 10 Jun 2022, 15:07

ahk7 wrote:
10 Jun 2022, 11:21
I find that not all methods work all the time for whatever reason, so I try byId byName and Xpath - often one them will work (although in principle they all should in most cases but whatever gets the job done)

You could try

Code: Select all

Element := document.getElementsbyXpath("//*[@id=""205123""]")
Element[0].click() ; Remember it returns an object so use [number].something
Thanks, that method seems to work for everything I've tried so far.

The reason I wanted to use the element id was because that buttons' ID varies depending on the last six digits of the webpages URL...

It was easier to just take the last 6 digits, put that into a variable (Var1) then do something that I've been doing with IE to click the button:

Code: Select all

Wb.document.getElementById(Var1).click()
Using the xpath works for me when I can set it up exactly how you did.

However it's been a challenge making it work with a variable in there because of the 4 quotes in there either creating an illegal character error or when I add more quotes, it just not working.

Code: Select all

document.getElementsbyXpath("//*[@id=""Var1""]")

Nivol
Posts: 6
Joined: 31 Jul 2021, 09:54

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by Nivol » 10 Jun 2022, 15:19

Xeo786 wrote:
10 Jun 2022, 11:14
Yes, I tried to assign it to a hotkey and made sure to wait for the webpage to load before pressing it.

I didn't know about the element.error so thanks for showing how it works.

When I tried it out I got a "no such element" message box.

I'm fairly certain the element is there because it works with AHK IE, Chrome Console and it's in the xpath (though not sure if it works the same way).

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

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by ahk7 » 10 Jun 2022, 16:22

Perhaps

Code: Select all

id:=205123
document.getElementsbyXpath("//*[@id=""" id """]")

winkieduck
Posts: 1
Joined: 02 Feb 2017, 11:39

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by winkieduck » 11 Jun 2022, 01:12

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

Image
Attachments
image.png
image.png (24.29 KiB) Viewed 2626 times

HardyMcFly
Posts: 2
Joined: 02 Feb 2022, 19:08

Re: Rufaydium WebDriver 1.6.1 (no selenium/websocket)

Post by HardyMcFly » 11 Jun 2022, 04:00

Hi
thanks for your work. It is what i needed.
How can I force the next command, before the other command is done?
For example send the next command before site finished loading.
Thanks

Post Reply

Return to “Scripts and Functions (v1)”