Using Selenium with AutoHotkey- Cross browser automation!
Re: Using Selenium with AutoHotkey- Cross browser automation!
SeleniumBasic is a Visual Basic selenium wrapper program providing the COM interface method that AHK uses to control it.
Re: Using Selenium with AutoHotkey- Cross browser automation!
- I wrote a script to get the webpage titles/urls in Chrome v69.
- Some issues: it doesn't know how many tabs there are, the order is unspecified, it activates each tab (although very quickly).
- If anyone can improve this, I would be grateful.
- Links:
[post by CH HAN and response by malcev]
Using Selenium with AutoHotkey- Cross browser automation! - Page 4 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 49#p231849
[get tab count and other tab info]
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947
- Btw is anyone having any success with Firefox and SeleniumBasic? It says here that people have to downgrade to Firefox v46.0.1 to use it with SeleniumBasic.
FireFox, Chrome, Edge, Opera Drivers are not working · Issue #133 · florentbr/SeleniumBasic · GitHub
https://github.com/florentbr/SeleniumBasic/issues/133
- Also, it looks like there has been no activity since Mar 2, 2016.
Release SeleniumBasic v2.0.9.0 · florentbr/SeleniumBasic · GitHub
https://github.com/florentbr/SeleniumBa ... g/v2.0.9.0
- Some issues: it doesn't know how many tabs there are, the order is unspecified, it activates each tab (although very quickly).
- If anyone can improve this, I would be grateful.
Code: Select all
;[Google Chrome + SeleniumBasic installation instructions]
;Using Selenium with AutoHotkey- Cross browser automation! - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=32323&p=151996#p151996
w:: ;chrome + selenium basic - open urls
Loop, 3
{
Run, % "chrome.exe --remote-debugging-port=9222 https://en.wikipedia.org/wiki/" Chr(64+A_Index)
Sleep, 800
}
return
q:: ;chrome + selenium basic - get titles/urls
vOutput := ""
oDriver := ChromeGet()
Loop, 3
{
vOutput .= oDriver.Window.Title "`r`n" oDriver.Url "`r`n`r`n"
oDriver.SwitchToNextWindow ;change tab
}
MsgBox, % Clipboard := RTrim(vOutput, "`r`n") "`r`n"
return
;[ChromeGet function]
;note: start Chrome with: chrome.exe --remote-debugging-port=9222
;Using Selenium with AutoHotkey- Cross browser automation! - Page 2 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=32323&p=181299#p181299
;slight modification by jeeswg of ChromeGet() by tmplinshi
ChromeGet(IP_Port:="127.0.0.1:9222")
{
local
driver := ComObjCreate("Selenium.ChromeDriver")
driver.SetCapability("debuggerAddress", IP_Port)
driver.Start()
return driver
}
[post by CH HAN and response by malcev]
Using Selenium with AutoHotkey- Cross browser automation! - Page 4 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 49#p231849
[get tab count and other tab info]
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947
- Btw is anyone having any success with Firefox and SeleniumBasic? It says here that people have to downgrade to Firefox v46.0.1 to use it with SeleniumBasic.
FireFox, Chrome, Edge, Opera Drivers are not working · Issue #133 · florentbr/SeleniumBasic · GitHub
https://github.com/florentbr/SeleniumBasic/issues/133
- Also, it looks like there has been no activity since Mar 2, 2016.
Release SeleniumBasic v2.0.9.0 · florentbr/SeleniumBasic · GitHub
https://github.com/florentbr/SeleniumBa ... g/v2.0.9.0
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Using Selenium with AutoHotkey- Cross browser automation!
You can do it like this:it doesn't know how many tabs there are
Code: Select all
loop % oDriver.Windows.Count
msgbox % oDriver.Windows.Item(A_Index).Title "`n" oDriver.Url
A I know it is impossible to get info from tab without activating it using selenium.it activates each tab
The order does not depend on position order, but depends from switch order.the order is unspecified
For example if You switch 1-2-3, tab index of number 3 will be 1 and number 1 will be 3.
As a workaround You can compare each tab position through iaccessible interface.
-
- Posts: 19
- Joined: 15 Jul 2016, 19:57
Re: Using Selenium with AutoHotkey- Cross browser automation!
I just started messing with this Selenium stuff last night. So far, it works great. I'm hoping I'll be allowed to use it on my work computer to automate a bunch of the useless crap we have to go through to complete the simplest of tasks. Anyhow, I'm trying to mash up a couple of scripts from earlier in this thread and I'm having a little trouble getting what I want. When I run this, I want it to first look and see if I already have Chrome open, and if so, use the existing window. If Chrome is not currently running, run it and go to the site I need. This is what I have:
If I already have Chrome running, it works okay -- it goes to my most recently tab and opens the new url there (which is not really ideal -- I'd rather open a new tab in most cases, but I'll deal with that part later). But if I don't have Chrome running yet, nothing happens. If I manually open Chrome after trying to run the script, the script will pick up at that point and hijack a tab.
I have tried every version of the if/else statement above I can think of -- If !WinExist, switching the order of the statements, only having one of the statements (If but no else).
Code: Select all
#!2::
If WinNotExist, ahk_exe chrome.exe {
Run,chrome.exe --remote-debugging-port=9222
}
Else {
WinActivate, ahk_exe chrome.exe
}
driver := ComObjCreate("Selenium.ChromeDriver")
driver.SetCapability("debuggerAddress", "127.0.0.1:9222")
driver.Get("https://www.bing.com")
MsgBox, % driver.Title
Return
If I already have Chrome running, it works okay -- it goes to my most recently tab and opens the new url there (which is not really ideal -- I'd rather open a new tab in most cases, but I'll deal with that part later). But if I don't have Chrome running yet, nothing happens. If I manually open Chrome after trying to run the script, the script will pick up at that point and hijack a tab.
I have tried every version of the if/else statement above I can think of -- If !WinExist, switching the order of the statements, only having one of the statements (If but no else).
-
- Posts: 19
- Joined: 15 Jul 2016, 19:57
Re: Using Selenium with AutoHotkey- Cross browser automation!
Immediately after posting I thought of another thing to try -- IfWinNotExist -- which worked. I wasn't going to bother with it since the documentation said it's deprecated, but Win[Not]Exist() didn't work either, so I thought, why not?
So now I at least have this functioning pretty well:
So now I at least have this functioning pretty well:
Code: Select all
#!2::
IfWinNotExist, ahk_exe chrome.exe
{
Run,chrome.exe --remote-debugging-port=9222
}
Else
{
WinActivate, ahk_exe chrome.exe
}
driver := ComObjCreate("Selenium.ChromeDriver")
driver.SetCapability("debuggerAddress", "127.0.0.1:9222")
driver.AddArgument("--user-data-dir=C:\Users\Paige\AppData\Local\Google\Chrome\User Data\Default") ; Use local chrome profile
driver.AddArgument("disable-infobars") ;disable notification "chrome is being controlled by automated test software"
driver.SetProfile("C:\Users\Paige\AppData\Local\Google\Chrome\User Data\Default") ;set profile path
driver.Get("https://www.bing.com")
MsgBox, % driver.Title
Return
Re: Using Selenium with AutoHotkey- Cross browser automation!
Hello,
there is a promising new toy, especially for (but not only) Firefox users (like me):
intoli/remote-browser: A low-level browser automation framework built on top of the Web Extensions API standard.
And it can connect to an already running browser!
No further infos yet, I'm too excited!
Greetings
hotkeyguy
there is a promising new toy, especially for (but not only) Firefox users (like me):
intoli/remote-browser: A low-level browser automation framework built on top of the Web Extensions API standard.
And it can connect to an already running browser!
No further infos yet, I'm too excited!

Greetings
hotkeyguy
Re: Using Selenium with AutoHotkey- Cross browser automation!
Hi @Joe Glines
Thanks you for all this stuff you give on threads and website...
I create some functions to simplify IE automantion: https://autohotkey.com/boards/viewtopic ... 27#p249027
Could be usefull for someone here
Thanks you for all this stuff you give on threads and website...
I create some functions to simplify IE automantion: https://autohotkey.com/boards/viewtopic ... 27#p249027
Could be usefull for someone here
-
- Posts: 4
- Joined: 26 Sep 2017, 19:10
Re: Using Selenium with AutoHotkey- Cross browser automation!
Hi,
I've been following along with Joe Glines' tutorial and have installed SeleniumBasic and chromedriver under Joe's direction and have them under /Program Files/.
However, when I try to run a test script to launch chrome (See: https://p.ahkscript.org/?p=c9351c88) I get an error on line 4 that states "The system cannot find the file specified"
Why is this? Have I missed something? Thanks!
I've been following along with Joe Glines' tutorial and have installed SeleniumBasic and chromedriver under Joe's direction and have them under /Program Files/.
However, when I try to run a test script to launch chrome (See: https://p.ahkscript.org/?p=c9351c88) I get an error on line 4 that states "The system cannot find the file specified"
Why is this? Have I missed something? Thanks!
Re: Using Selenium with AutoHotkey- Cross browser automation!
Code: Select all
#SingleInstance, Force
Del::
driver := ComObjCreate("Selenium.ChromeDriver") ; Start with Chrome
driver.Get("http://duckduckgo.com/") ; Navigate to a webpage
MsgBox here
return
-
- Posts: 4
- Joined: 26 Sep 2017, 19:10
Re: Using Selenium with AutoHotkey- Cross browser automation!
Code: Select all
#SingleInstance, Force
Del::
driver := ComObjCreate("Selenium.ChromeDriver") ; Start with Chrome
driver.Get("http://duckduckgo.com/") ; Navigate to a webpage
MsgBox here
return
- Sabestian Caine
- Posts: 334
- Joined: 12 Apr 2015, 03:53
Re: Using Selenium with AutoHotkey- Cross browser automation!
Hello dear Joe Glines.Joe Glines wrote: ↑08 Dec 2017, 19:48@CH HAN- thanks for publishing that! I made some minor tweaks and demonstrate it's usage here.![]()
Code: Select all
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver driver.Get("http://the-automator.com") ;********************find and click text*********************************** keyword:="Continue reading" ; keyword you want to find- Note Case sensitive if(driver.FindElementByXPath("//*[text() = '" keyword "']")) driver.FindElementByXPath("//*[text() = '" keyword "']").click()
Sir, I am trying to automate chrome by selenium and i want to get the URL from a button or link in a webpage. I am unable to retrieve the URL from a specific button or link in a webpage. For this i have asked a question in AutoHotKey help form. The link of my question is this-
https://autohotkey.com/boards/viewtopic ... 76&t=60232
I request you to please solve this issue. Thanks a lot sir...


I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
- Sabestian Caine
- Posts: 334
- Joined: 12 Apr 2015, 03:53
Re: Using Selenium with AutoHotkey- Cross browser automation!
Problem solved sir!!!!Joe Glines wrote: ↑08 Dec 2017, 19:48@CH HAN- thanks for publishing that! I made some minor tweaks and demonstrate it's usage here.![]()
Code: Select all
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver driver.Get("http://the-automator.com") ;********************find and click text*********************************** keyword:="Continue reading" ; keyword you want to find- Note Case sensitive if(driver.FindElementByXPath("//*[text() = '" keyword "']")) driver.FindElementByXPath("//*[text() = '" keyword "']").click()
this is working-
Code: Select all
MsgBox % driver.findElementsByClass("forumtitle").item[1].Attribute("href")
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
Who is online
Users browsing this forum: No registered users and 6 guests