Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by boiler » 29 Nov 2022, 08:08

automater wrote: I'm trying to set the value of a box using AHK variables but the % signs are breaking my code:
Note the different assignment operator and no % signs:

Code: Select all

Page.querySelector(".sc-pcZJD.iNHvZE").value := reportName
Explained: Expressions

automater wrote: Also, I don't have the foundational web-page knowledge to use Rufaydium to its fullest. The browser contols I understand (reloads, new tabs, print, etc). Specifically, I don't know what the heck are classes, divs, spans, IDs, xpaths, paths, etc. The problem is that I don't even know what sub-field of knowledge I need to learn is called. My question: What language and subfield is this so I can understand Rufaydium fastest? From a few Google searches, is it something like 'manipulating documents' or 'controlling HTML'? Please point me in the right direction. And please don't be top level like 'you need to learn HTML' instead, kindly point me to the name of the subset of knowledge I need for understanding the web-page code.
You might try googling "find elements using Xpath" and "find elements using css selector"

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 29 Nov 2022, 08:45

boiler wrote:
29 Nov 2022, 08:08
automater wrote: I'm trying to set the value of a box using AHK variables but the % signs are breaking my code:
Note the different assignment operator and no % signs:

Code: Select all

Page.querySelector(".sc-pcZJD.iNHvZE").value := reportName
Explained: Expressions

automater wrote: Also, I don't have the foundational web-page knowledge to use Rufaydium to its fullest. The browser contols I understand (reloads, new tabs, print, etc). Specifically, I don't know what the heck are classes, divs, spans, IDs, xpaths, paths, etc. The problem is that I don't even know what sub-field of knowledge I need to learn is called. My question: What language and subfield is this so I can understand Rufaydium fastest? From a few Google searches, is it something like 'manipulating documents' or 'controlling HTML'? Please point me in the right direction. And please don't be top level like 'you need to learn HTML' instead, kindly point me to the name of the subset of knowledge I need for understanding the web-page code.
You might try googling "find elements using Xpath" and "find elements using css selector"
Thanks so much @boiler. I'm stepping out now but excited to implement your feedback when I return. Re: Knowledge subset - Perfect! That's exactly what I needed. I'll start there.

A couple other questions if you don't mind:
1) This works in Dev Console:

Code: Select all

document.getElementById("includeZeroImpressionEntities").checked = false
But this doesn't work when I run my script:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked = false
Nothing is happening and I have no idea why.

2) When using Rufaydium's commands (e.g. getting elements), how do I know when I need the dot (".name") and when I don't? Are dots for classes only? What subset of knowledge is this? Some subset of JavaScript? If you can point me in the right direction here as well, I'd really appreciate it.

Thanks.

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by boiler » 29 Nov 2022, 09:20

automater wrote: ... this doesn't work when I run my script:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked = false
Nothing is happening and I have no idea why.
Again, you need to use the expression version of the assignment operator:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked := false
It is important that you apply correct AHK syntax when going from what works in the dev tools to your AHK script.

automater wrote: 2) When using Rufaydium's commands (e.g. getting elements), how do I know when I need the dot (".name") and when I don't? Are dots for classes only? What subset of knowledge is this? Some subset of JavaScript? If you can point me in the right direction here as well, I'd really appreciate it.
I'm not exactly sure what you mean. The dots are separators between elements/levels in an object. You need to use them until you get to the level of what you need. If you don't get all the way down to a property such as .name, then the result is typically an object, such as an array of items or an object that has different properties (or an even higher level that has a lot of "branches"). You will learn more about those kinds of things when going through the lessons found at my google suggestions.

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 29 Nov 2022, 13:06

boiler wrote:
29 Nov 2022, 09:20
automater wrote: ... this doesn't work when I run my script:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked = false
Nothing is happening and I have no idea why.
Again, you need to use the expression version of the assignment operator:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked := false
It is important that you apply correct AHK syntax when going from what works in the dev tools to your AHK script.

automater wrote: 2) When using Rufaydium's commands (e.g. getting elements), how do I know when I need the dot (".name") and when I don't? Are dots for classes only? What subset of knowledge is this? Some subset of JavaScript? If you can point me in the right direction here as well, I'd really appreciate it.
I'm not exactly sure what you mean. The dots are separators between elements/levels in an object. You need to use them until you get to the level of what you need. If you don't get all the way down to a property such as .name, then the result is typically an object, such as an array of items or an object that has different properties (or an even higher level that has a lot of "branches"). You will learn more about those kinds of things when going through the lessons found at my google suggestions.
Thanks @boiler :)

Re: Dots - So I think I need to do some homework on properties, objects, etc. so I can understand the syntax. I already found a promising video on Web Elements. I think I can learn a lot of relevant stuff from content intended for Selenium users, so I might bounce off of such materials for now.

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 29 Nov 2022, 14:58

boiler wrote:
29 Nov 2022, 09:20
automater wrote: ... this doesn't work when I run my script:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked = false
Nothing is happening and I have no idea why.
Again, you need to use the expression version of the assignment operator:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked := false
It is important that you apply correct AHK syntax when going from what works in the dev tools to your AHK script.

automater wrote: 2) When using Rufaydium's commands (e.g. getting elements), how do I know when I need the dot (".name") and when I don't? Are dots for classes only? What subset of knowledge is this? Some subset of JavaScript? If you can point me in the right direction here as well, I'd really appreciate it.
I'm not exactly sure what you mean. The dots are separators between elements/levels in an object. You need to use them until you get to the level of what you need. If you don't get all the way down to a property such as .name, then the result is typically an object, such as an array of items or an object that has different properties (or an even higher level that has a lot of "branches"). You will learn more about those kinds of things when going through the lessons found at my google suggestions.
Thanks for your help thus far @boiler. I've made a bit of progress in my project with your input.

I've run into a couple of other issues though.
1) This doesn't work (I read through the Expressions page and I can't seem to figure out what's the issue):

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked := false
I've also tried these:

Code: Select all

Page.getElementById([b]'[/b]includeZeroImpressionEntities[b]'[/b]).checked := false
Page.getElementById("[b].[/b]includeZeroImpressionEntities").checked := false
Any ideas?

Also, my aria-label click is now working thankfully :D :

Code: Select all

Page.querySelector("[aria-label='Choose Tuesday, November 29, 2022 as your end date.']").click()
I'm trying to make the date dynamic now but it's not working. Here's what I've done:

Code: Select all

FormatTime, TimeString,, LongDate
endDate := """[aria-label='Choose " TimeString " as your end date.']"""
When I test endDate output in a MsgBox, the output is exactly what I need including the double quotes enclosing the line (per the working line above) yet none of these attempts to use the variable works:

Code: Select all

Page.querySelector(endDate).click()
Page.querySelector(%endDate%).click()
Sorry for the bother but really trying to research, understand, and trial and error on my end but I just can't get it to work :headwall:

As I'm typing I just came up with another idea...maybe I can create a variable with everything from page to the end of the aria-label then add the click, so: var.click()

Shooting from the hip here but I'm not giving up.

Any ideas @Xeo786?

Thanks guys,
Jon.

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by boiler » 29 Nov 2022, 15:25

I don't know the details of Rufaydium specifically or of the HTML you're acting on to be able to give you specific feedback. I can tell you that the version you showed with % around endDate is wrong. You typically don't use % in expressions except for advanced cases which you aren't using.

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 29 Nov 2022, 16:51

boiler wrote:
29 Nov 2022, 15:25
I don't know the details of Rufaydium specifically or of the HTML you're acting on to be able to give you specific feedback. I can tell you that the version you showed with % around endDate is wrong. You typically don't use % in expressions except for advanced cases which you aren't using.
Thanks boiler. I figured I didn't need the % - I was out of ideas and trying everything :lol:

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 29 Nov 2022, 18:56

I'm trying to click on the first link with certain partial text.

I've tried this but it's not working:

Code: Select all

Page.findelement(by.Plinktext,"https://advertising.amazon.com/bulksheet/downloadReport").Click()
Based on the ReadMe, I think I need this somewhere:

Code: Select all

Class by
{
	static Plinktext := "https://advertising.amazon.com/bulksheet/downloadReport"
}
But if Plinktext above is a variable to which I'm assigning the partial text, then I'm not sure how to incorporate it into the following code:

Code: Select all

Page.findelement(by.selector,"selectorparameter")
Any help is appreciated.

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 30 Nov 2022, 02:10

automater wrote:
29 Nov 2022, 18:56
I'm trying to click on the first link with certain partial text.

I've tried this but it's not working:

Code: Select all

Page.findelement(by.Plinktext,"https://advertising.amazon.com/bulksheet/downloadReport").Click()
Based on the ReadMe, I think I need this somewhere:
You can see by.class, all the parameters supported by Session.findelement() or .findelements(),

"by link text" mean the full Text of a link and "by partial link text" mean the partial text of a link.
For example, if there is hyperlink on a webpage with the following HTML

Code: Select all

<a href="https://github.com/Xeo786/Rufaydium-Webdriver#by-class">click here</a>
This Html has href link and innerText says click here which is visible on page. so we need to pass use that text not the link

Code: Select all

Page.findelement(by.linktext,"click here").Click()
for the partial query you need to pass partial text

Code: Select all

Page.findelement(by.plinktext,"here").Click()
for multiple elements

Code: Select all

Page.findelements(by.plinktext,"print")[2].Click()


I have only used by.selector and by.TagName so far, what I have suggested above, is what the documentation says, if you face any error or bug in Rufaydium please point it out.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 30 Nov 2022, 06:44

@Xeo786 The link text worked perfectly!!! Amazing!

I'm stuck with two other things - I'd appreciate any input:
1) This works in Dev Console:

Code: Select all

document.getElementById("includeZeroImpressionEntities").checked = false
But none of these work when I run my script:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked = false
Page.getElementById("includeZeroImpressionEntities").checked := false
Page.getElementById('includeZeroImpressionEntities').checked = false
Page.getElementById('includeZeroImpressionEntities').checked := false
No idea what to do to uncheck that box.

2) I'm using an aria-label to click a date in a pop up calendar which works perfectly:

Code: Select all

Page.querySelector("[aria-label='Choose Tuesday, November 29, 2022 as your end date.']").click()
Where I'm stuck is that I'm trying to make it dynamic by having AHK generate the date in the middle of the label:

Code: Select all

FormatTime, TimeString,, LongDate
endDate := """[aria-label='Choose " TimeString " as your end date.']"""
When I MsgBox endDate, the output perfectly matches the working line above - the problem is that I'm not sure how to merge this with querySelector...these two attempts have not worked:

Code: Select all

Page.querySelector(endDate).click()
Page.querySelector(%endDate%).click()
I've also tried single quotes instead.

I've finally tried making everything from Page to the end of the aria-label a variable so I could then use something like this:

Code: Select all

var.click()
That also did not work and I'm out of ideas. Any help is appreciated.

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 30 Nov 2022, 07:15

automater wrote:
30 Nov 2022, 06:44
I'm stuck with two other things - I'd appreciate any input:
1) This works in Dev Console:

Code: Select all

document.getElementById("includeZeroImpressionEntities").checked = false
But none of these work when I run my script:

Code: Select all

Page.getElementById("includeZeroImpressionEntities").checked = false
Page.getElementById("includeZeroImpressionEntities").checked := false
Page.getElementById('includeZeroImpressionEntities').checked = false
Page.getElementById('includeZeroImpressionEntities').checked := false
No idea what to do to uncheck that box.
You can get checked status but you cannot set checked status, I haven't implemented that because one can check and uncheck just by clicking

Code: Select all

e := Page.getElementById("includeZeroImpressionEntities")
msgbox, % e.checked 
e.click()
msgbox, % e.checked
e.click()
msgbox, % e.checked
automater wrote:
30 Nov 2022, 06:44
2) I'm using an aria-label to click a date in a pop up calendar which works perfectly:

Code: Select all

Page.querySelector("[aria-label='Choose Tuesday, November 29, 2022 as your end date.']").click()
Where I'm stuck is that I'm trying to make it dynamic by having AHK generate the date in the middle of the label:

Code: Select all

FormatTime, TimeString,, LongDate
endDate := """[aria-label='Choose " TimeString " as your end date.']"""
When I MsgBox endDate, the output perfectly matches the working line above - the problem is that I'm not sure how to merge this with querySelector...these two attempts have not worked:

Code: Select all

Page.querySelector(endDate).click()
Page.querySelector(%endDate%).click()
try this and you will see why its not working

Code: Select all

FormatTime, TimeString,, LongDate
a := "[aria-label='Choose Tuesday, November 29, 2022 as your end date.']"
b := "[aria-label='Choose " TimeString " as your end date.']"
c := """[aria-label='Choose " TimeString " as your end date.']"""
msgbox, % a "`n" b "`n" c
; try b It would work 
return
automater wrote:
30 Nov 2022, 06:44
I've finally tried making everything from Page to the end of the aria-label a variable so I could then use something like this:

Code: Select all

var.click()
Session in your case its variable page, can return with any desired element/elements as a WDElement class object, I already have mentioned the example above about checking e.click().
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 30 Nov 2022, 10:11

Xeo786 wrote:
30 Nov 2022, 07:15
Thanks a lot for your help @Xeo786 - everything works now!!! :superhappy:

Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Sadaosh1970 » 01 Dec 2022, 22:07

Hello to everyone. I read all the posts and README.md. I can already automate part of my boring and repetitive work.
Thanks to the @Xeo786!
I use the Gecko driver.

I have three questions:
1) When I use "Page := FF.getSession(1,2)" and then close this tab manually, I lose access to the Webdriver. After a few seconds, the file "ActiveSessions.ini" has its contents only [geckodriver].
2) When Using "Page := FF.getSessionByTitle("some title")" the gecko brower closes, but "ActiveSessions.ini" contains something like this [geckodriver] 8588c453c-9f14-4830-a12b-ba53a8131c59=8588c453c-9f14-4830-a12b-ba53a8131c59.
3) How to determine the number of the tab that is active?

Thank you to anyone who can help me!

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 02 Dec 2022, 00:44

Sadaosh1970 wrote:
01 Dec 2022, 22:07
I have three questions:
1) When I use "Page := FF.getSession(1,2)" and then close this tab manually, I lose access to the Webdriver. After a few seconds, the file "ActiveSessions.ini" has its contents only [geckodriver].
You are not supposed to close the window manually, it closed for you but not for the geckodriver, Rufaydium actually terminates any session which it finds unresponsive,
Spoiler
Sadaosh1970 wrote:
01 Dec 2022, 22:07
2) When Using "Page := FF.getSessionByTitle("some title")" the gecko brower closes, but "ActiveSessions.ini" contains something like this [geckodriver] 8588c453c-9f14-4830-a12b-ba53a8131c59=8588c453c-9f14-4830-a12b-ba53a8131c59.
That's Unique ID for a session, a kind of rest call api access,
Actually every chromium-based driver has this API that retrieves active sessions detail with their unique IDs, but geckodriver lacks, idk why maybe they think its best for secure webdriver access, so the user has to maintain sessions detail, in the case of Rufaydium it is done by AHK's read and write ini. Rufaydium only delete UID entry from ini when it finds UID in question unresponsive,
Sadaosh1970 wrote:
01 Dec 2022, 22:07
3) How to determine the number of the tab that is active?
This is how you can check what tab has which number.

Code: Select all

for n, handle in Page.GetTabs()
{
	Page.switch(handle)
	msgbox, % "Title: " page.title "`nUrl: " Page.url "`n is number : " n
}
Edit: just updated Rufaydium. Page.Detail() was not working for firefox now its working.

Code: Select all

msgbox, % json.dump(Page.detail(),1) ; it will return with UID of tabs URL and title
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Sadaosh1970 » 02 Dec 2022, 12:38

Thank you so much @Xeo786!
This helps me understand a little more about Rufaydium.

I have one more question.
I opened one page and another page in the second Tab.
When I try to use the command below, Firefox closes.

Page := FF.getSession(1,1) ; 1ª active session1, tab 1 ; this works
some code here...

Page := FF.getSessionByTitle("Title of second page") ; this close Firefox
Page := FF.getSessionByUrl("https:// some url") ; this close Firefox

What am I doing wrong?

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 03 Dec 2022, 03:27

Sadaosh1970 wrote:
02 Dec 2022, 12:38
Thank you so much @Xeo786!
This helps me understand a little more about Rufaydium.

I have one more question.
I opened one page and another page in the second Tab.
When I try to use the command below, Firefox closes.

Page := FF.getSession(1,1) ; 1ª active session1, tab 1 ; this works
some code here...

Page := FF.getSessionByTitle("Title of second page") ; this close Firefox
Page := FF.getSessionByUrl("https:// some url") ; this close Firefox

What am I doing wrong?
for GeckoDriver Rufaydium was only storing Session ID now it will store the debugger URL too,
Just update Rufaydium and fixed that lacking ability. test and following code is working fine
Make sure create a session with latest Rufaydium so it will update INI with the debugger address before trying this code

Code: Select all

Page := FF.getSession(1,1) ; 1ª active session1, tab 1 ; this works
msgbox, % page.url
Page := FF.getSessionByTitle("autohotkey") ; this close Firefox
msgbox, % page.title
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Sadaosh1970 » 03 Dec 2022, 05:54

First, thanks for the reply @Xeo786!!!

Rufaydium-Webdriver-main.zip (today download, extract all files)

Code: Select all

; Tab1 = twitter
Page := FF.getSession(1,1) ; this works (twitter)
MsgBox, % page.title() ; Ok 
Sleep 500


; Tab2 = Autohotkey
; Page := FF.getSession(1,2) ; this works ( changes Autohotkey Page)

Page := FF.getSessionByTitle("Autohotkey") ; (Nothing happens, stay on twitter)
MsgBox, % page.title() ; Blank

Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 03 Dec 2022, 08:04

Sadaosh1970 wrote:
03 Dec 2022, 05:54
First, thanks for the reply @Xeo786!!!

Rufaydium-Webdriver-main.zip (today download, extract all files)

Code: Select all

; Tab1 = twitter
Page := FF.getSession(1,1) ; this works (twitter)
MsgBox, % page.title() ; Ok 
Sleep 500


; Tab2 = Autohotkey
; Page := FF.getSession(1,2) ; this works ( changes Autohotkey Page)

Page := FF.getSessionByTitle("Autohotkey") ; (Nothing happens, stay on twitter)
MsgBox, % page.title() ; Blank

Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Firefox Json List from debugger address does not return with Page title, unlike chrome. A fix has been applied, now it will work.
tried following code with latest Rufaydium

Code: Select all

FF := new Rufaydium("geckodriver")
f1::
FFPage := FF.NewSession()
FFPage.url := "https://github.com/Xeo786/Rufaydium-Webdriver"
FFPage.NewTab()
FFPage.url := "https://www.google.com/"
return

f5::
Page := FF.getSession(1,1) ; 1ª active session1, tab 1 ; this works
msgbox, % page.url
Page := FF.getSessionByTitle("google") ; this close Firefox
msgbox, % page.title

Page := FF.getSessionByTitle("ABCD") ; this close Firefox
msgbox, % page.title
if !object(Page)
    msgbox, There is no session class object inside Page variable
return



f12::
FF := new Rufaydium("geckodriver")
FF.QuitAllSessions() ; close all session 
FF.Driver.Exit() ; then exits driver
msgbox, all session closed and Driver Exitted
exitapp
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Sadaosh1970 » 03 Dec 2022, 12:32

Thank you!!! @Xeo786!!! :clap:
It's working perfectly!! :bravo:
You have no idea how you helped me!
Rufaydium helps me a lot!!!

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 03 Dec 2022, 12:38

Sadaosh1970 wrote:
03 Dec 2022, 12:32
Thank you!!! @Xeo786!!! :clap:
It's working perfectly!! :bravo:
You have no idea how you helped me!
Rufaydium helps me a lot!!!
Thanks to you, I am able to fix a few crucial bugs against geckodriver.
"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)”