Sorry, probably poorly worded.
I need an exact example of how you generated the error message
".error says "cannot create default profile directory" hmmm " with .error.
Thank you..
Sorry, probably poorly worded.
".error says "cannot create default profile directory" hmmm " with .error.
Sorry for the confusion, I was using phone to reply and failed to read properly
its there in newsession() https://github.com/Xeo786/Rufaydium-Webdriver/blob/main/Rufaydium.ahk#L56
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.thalesduarte wrote: ↑27 Apr 2022, 11:40Can you share an example script by filling out a form on the web and clicking the SUBMIT button?
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
Code: Select all
msgbox, % Session.title() ; will show active title
msgbox, % Session.url() ; will show active title
Bad question again.Xeo786 wrote: ↑28 Apr 2022, 03:00Also updated documents https://github.com/Xeo786/Rufaydium-Webdriver/blob/main/README.md#webdriver-sessionsCode: Select all
msgbox, % Session.title() ; will show active title msgbox, % Session.url() ; will show active title
Code: Select all
Session := Chrome.getSessionByUrl(URL)
Session2 := Chrome.getSessionByTitle(Title)
You can use SwitchbyTitle() or SwitchbyURL()Milchmann wrote: ↑28 Apr 2022, 06:44Bad question again.Xeo786 wrote: ↑28 Apr 2022, 03:00Also updated documents https://github.com/Xeo786/Rufaydium-Webdriver/blob/main/README.md#webdriver-sessionsCode: Select all
msgbox, % Session.title() ; will show active title msgbox, % Session.url() ; will show active title
I started a session. Then I opened a page via the web driver and performed an action. Now I open a new TAB manually or through the opened page, which is now in the foreground.
I can't get over this new TABquery because I don't know what title or what url the active window has.Code: Select all
Session := Chrome.getSessionByUrl(URL) Session2 := Chrome.getSessionByTitle(Title)
Do you have a solution for this?
Thanks
Code: Select all
TabsDetail := Session.GetTabs()
msgbox, % json.dump(tabsDetail) ; this will show you how this object look like
; suppose there are 2 tabs
msgbox, % TabsDetail[1] ; will show first tabs unique Window ID
msgbox, % TabsDetail[2] ; will show second tabs unique Window ID
; you can switch to specific tab using that unique Window ID
Session.switch(TabsDetail[1]) ; will switch to first tab
; you can now check title and url for first tab
msgbox, % Session.title() "`n" Session.url()
Session.switch(TabsDetail[2]) ; will switch to second tab
; you can now check title and url for second tab
msgbox, % Session.title() "`n" Session.url()
This issue is the reason, I have added methods, will help access session / tabs by numbers
Code: Select all
#Include %A_ScriptDir%\lib
#Include Rufaydium.ahk
ChromeDriver := A_ScriptDir "\chromedriver.exe"
Return
F4::
Driver := new RunDriver(ChromeDriver) ; running driver
Chrome := new Rufaydium(Driver) ; this will return control over Browser
;TestWithIsLoading := 1 ;not working
TestWithIsLoading := 0 ;working
Chrome.capabilities := Capabilities.ChromeProfile
session := Chrome.NewSession()
Session.Maximize()
session.Navigate("https://www.autohotkey.com/")
SplashTextOn, , , Click Forums Button...
If TestWithIsLoading ;not working
{
While session.isLoading()
Sleep 200
session.findelement(by.linktext,"Forums").click()
}
else ;working
{
;Wait until Button Forums is available
MyButton := ""
While !IsObject(MyButton)
{
sleep, 200
MyButton := session.findelement(by.linktext,"Forums")
MyButton.click() ;Click on Forums Button
}
}
SplashTextOff
If TestWithIsLoading ;not working
{
While session.isLoading()
Sleep 200
}
else ;working
{
while !IsObject(TitleObj := Session.getElementsbyClassName("forumtitle")) ;Waiting for Forumssite
sleep, 200
}
Sleep 200
AllTitles := ""
For k, tag in TitleObj
AllTitles .= k "`t" tag.innertext "`n"
If TitleObj.length()
msgbox,4096,, % "There are " TitleObj.length() " Forumtitles`n`n" AllTitles "`n`nNow we click on advanced search looking for Rufaydium..."
else
msgbox,4096,, % "Ups, could not get the Forumtitles!"
SplashTextOn, , , Click Button Advanced Search...
loop
{
myClick := session.findelement(by.linktext,"Advanced search").click()
If myClick.error
break
Sleep 1000
SplashTextOn, , , Click again Button Advanced Search...
}
SplashTextOff
Sleep 200
session.findelement(by.selector,"#keywords").value := "Rufaydium" ;oder session.getelementbyid("keywords")
session.findelement(by.selector,"#page-body > form > div.panel.bg1 > div > fieldset > input.button1").click()
msgbox,4096,, % "Here are the topics for Rufaydium`n`nNow closing all sessions..."
Chrome.QuitAllSessions()
driver.exit()
return
Hi Xeo,Xeo786 wrote: ↑29 Apr 2022, 02:12This issue is the reason, I have added methods, will help access session / tabs by numbers
getSession(1) https://github.com/Xeo786/Rufaydium-Webdriver#new-session
SwitchTab(1) https://github.com/Xeo786/Rufaydium-Webdriver#switchtab-switchbytitle--switchbyurl
Thank you
BertGet the current tab
This example demonstrates how the background script can retrieve the currently focused tab.
This example requires Manifest V3 due to the use of Promises. Additionally, content scripts cannot use tabs.query.Code: Select all
//// background.js async function getCurrentTab() { let queryOptions = { active: true, currentWindow: true }; let [tab] = await chrome.tabs.query(queryOptions); return tab; }
Code: Select all
#Include Rufaydium.ahk
ChromeDriver := A_ScriptDir "\chromedriver.exe"
; choose different driver in order to automate different Browser
Driver := new RunDriver("ChromeDriver.exe") ; 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.elmundo.es/")
Page := ""
return
Code: Select all
IE := ComObjCreate("InternetExplorer.Application") ;~ Creation of hidden Internet Explorer instance to look up Deepl Translate and retrieve translation
IE.Visible := false
IE.Navigate(Path)
While IE.readyState!=4 || IE.document.readyState!="complete" || IE.busy ; Wait until page is loaded?
Sleep 50
While (IE.document.getElementsByTagName("textarea")[1].value = "") ;Since the conversion takes a second we want to wait till the value is filled otherwise the return will always be nothing
{
Sleep 50
If (A_Index >190) { ; Taking too long
; MsgBox ,,,Error`, starting, .5
IE.Quit
Return Result:="Translation failed"
}
}
Result := IE.document.getElementsByTagName("textarea")[1].value; THIS IS THE RESULT I WANT!
Code: Select all
msgbox % session.Detail()
msgbox % session.element.Displayed()
msgbox % session.element.enabled()
Code: Select all
Msgbox % Page.ExecuteSync("return window.devicePixelRatio")
Code: Select all
Element.scrollIntoView()
Hope following code would resolve issue
Code: Select all
Driver := new RunDriver(ChromeDriver) ; running driver
Chrome := new Rufaydium(Driver) ; this will return control over Browser
Session := Chrome.getSession(1) ; getting session by number as we do not know page title or url
; checking that session title and url
msgbox, % Session.title() "`n" Session.url()
if that page is google translate than it would be something likeNixcalo wrote: ↑02 May 2022, 07:46To be precise, I have a script that worked in IE that need migrate to Edge. It's like this.
This is what I want migrated into MS Edge, ideally, or otherwise Chrome/Firefox.Code: Select all
IE := ComObjCreate("InternetExplorer.Application") ;~ Creation of hidden Internet Explorer instance to look up Deepl Translate and retrieve translation IE.Visible := false IE.Navigate(Path) While IE.readyState!=4 || IE.document.readyState!="complete" || IE.busy ; Wait until page is loaded? Sleep 50 While (IE.document.getElementsByTagName("textarea")[1].value = "") ;Since the conversion takes a second we want to wait till the value is filled otherwise the return will always be nothing { Sleep 50 If (A_Index >190) { ; Taking too long ; MsgBox ,,,Error`, starting, .5 IE.Quit Return Result:="Translation failed" } } Result := IE.document.getElementsByTagName("textarea")[1].value; THIS IS THE RESULT I WANT!
Code: Select all
msEdgeDriver := A_ScriptDir "\msedgedriver.exe"
Driver := new RunDriver(msEdgeDriver) ; running driver
Chrome := new Rufaydium(Driver) ; this will return control over Browser
Page := Chrome.getSessionByUrl("https://translate.google.com") ; get session by url if we have previously created session
if !IsObject(Page)
{
Page := Chrome.NewSession()
Page.Navigate("https://translate.google.com/?hl=en&tab=rT&sl=auto&tl=es&op=translate")
; no need to check ready state as Webdriver basic has builtin await read this https://github.com/Xeo786/Rufaydium-Webdriver#await
}
TextArea := Page.querySelector("textarea")
TextArea.sendkey("xyz")
msgbox, % TextArea.value
I suspect I just answered that in above post, if not please elaborateMilchmann wrote: ↑04 May 2022, 08:591.
Can you still create a function for me?
viewtopic.php?p=460012#p460012
session.Detail() will return will page detail same as localhost:9222/json/listMilchmann wrote: ↑04 May 2022, 08:592.
I get atdoes not return any values.Code: Select all
msgbox % session.Detail() msgbox % session.element.Displayed() msgbox % session.element.enabled()
Code: Select all
msgbox % json.dump(session.Detail())
Code: Select all
Element := Session.querySelector(someselector)
msgbox, % "displayed: " Element.Displayed() "`nEnabled: " Element.enabled()
above code is working for me, you can calculate actual percentageMilchmann wrote: ↑04 May 2022, 08:593.Always brings as value 1 or 01 when I change the zoom in the browser. In the Java Console it brings me the correct results with for example 25% zoom = value "0.25".Code: Select all
Msgbox % Page.ExecuteSync("return window.devicePixelRatio")
Code: Select all
msgbox % round(Page.ExecuteSync("return window.devicePixelRatio") * 100,0) "%"
scrollIntoView() is not valid method
Code: Select all
Element := Session.querySelector(someselector)
Element.sendkey(json.null) ; for input elements
Element.click() ; for non input elements
Code: Select all
#SingleInstance force
ChromeDriver_Update()
return
ChromeDriver_Update(Dir_Chromedriver:=""){
; Function Updates the Chromedriver by checking the versions and downloading the latest chromedriver.
; Written by AHK_User
; Thanks to tmplinshi
Dir_Chromedriver := Dir_Chromedriver="" ? (FileExist(A_ScriptDir "\chromedriver.exe") ? A_ScriptDir "\chromedriver.exe" : "")
Dir_Chromedriver := Dir_Chromedriver="" ? RegexReplace(A_MyDocuments,"^(.*)\\.*","$1") "\AppData\Local\Google\Chrome\chromedriver.exe" : Dir_Chromedriver
SplitPath, Dir_Chromedriver, , Folder_Chromedriver
if FileExist(Dir_Chromedriver){
; Get Chromedriver version
Version_ChromeDriver := RunHide("""" Dir_Chromedriver """ --version")
Version_ChromeDriver := RegexReplace(Version_ChromeDriver, "[^\d]*([\.\d]*).*", "$1")
} else{
Version_ChromeDriver := "Error"
}
RegRead, File_ChromeExe, % "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Chrome.exe"
if (File_ChromeExe=""){
MsgBox, Failed to find the chrome.exe directory`nCurrent thread will exit.
Exit
}
FileGetVersion, Version_Chrome, % File_ChromeExe
Version_Chrome_ := RegexReplace(Version_Chrome, "\.\d+$")
Version_Chromedriver_ := RegexReplace(Version_Chromedriver, "\.\d+$")
; Check if versions are equal
if (Version_Chrome_=Version_Chromedriver_){
; Versions are the same
Return true
MsgBox,68,ChromeDriver,Current Chromedriver is same as Chromeversion.`nDo you still want to download?
IfMsgBox, No
{
exit
}
}
; Find the matching Chromedriver
oHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oHTTP.Open("GET", "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" Version_Chrome_, true)
oHTTP.Send()
oHTTP.WaitForResponse()
Version_Chromedriver := oHTTP.ResponseText
if InStr(Version_Chromedriver, "NoSuchKey"){
MsgBox,16,Testing,Error`nVersion_Chromedriver
return
}
; Download the Chromedriver
Url_ChromeDriver := "https://chromedriver.storage.googleapis.com/" Version_Chromedriver "/chromedriver_win32.zip"
URLDownloadToFile, %Url_ChromeDriver%, %A_ScriptDir%/chromedriver_win32.zip
; Unzip Chromedriver_win32.zip
fso := ComObjCreate("Scripting.FileSystemObject")
AppObj := ComObjCreate("Shell.Application")
FolderObj := AppObj.Namespace(A_ScriptDir "\chromedriver_win32.zip")
FileCreateDir, Folder_Chromedriver "\Backup"
FileMoveDir, Dir_Chromedriver, Folder_Chromedriver "\Backup\", 1
FileObj := FolderObj.ParseName("chromedriver.exe")
AppObj.Namespace(Folder_Chromedriver "\").CopyHere(FileObj, 4|16)
; Clean up the zipfile
FileDelete, % A_ScriptDir "\chromedriver_win32.zip"
return true
}
RunHide(Command) {
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
Run, %ComSpec%,, Hide, cPid
WinWait, ahk_pid %cPid%
DetectHiddenWindows, %dhw%
DllCall("AttachConsole", "uint", cPid)
Shell := ComObjCreate("WScript.Shell")
Exec := Shell.Exec(Command)
Result := Exec.StdOut.ReadAll()
DllCall("FreeConsole")
Process, Close, %cPid%
Return Result
}
I think the exact location of browsers can be found on the registry. I had some code a while ago that retrieved the defaults browser location but it could be tweaked to find the exact location of any installed program.
@RaptorX: Thanks for the tip, I found the location and updated my previous post.
Code: Select all
RegRead, File_ChromeExe, % "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Chrome.exe"
Return to “Scripts and Functions (v1)”
Users browsing this forum: No registered users and 184 guests