Using Selenium with AutoHotkey- Cross browser automation!

Helpful script writing tricks and HowTo's
Mike__
Posts: 11
Joined: 25 Jul 2018, 14:36

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 14:30

I am new to this but I get the following error... what's wrong? Windows 7, lastest chrome driver and chrome.

---------------------------
test.ahk
---------------------------
Error: 0xA00A0021 -
Source: Selenium
Description: SessionNotCreatedError
session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"90E432F756CAFB226C36A98FBE702F35","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=MYIP)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
HelpFile: (null)
HelpContext: 0

Specifically: Get

Line#
004: SetWorkingDir,%A_ScriptDir%
009: Return
009: Reload
009: Return
013: driver := ComObjCreate("Selenium.ChromeDriver")
014: drive.start("CHROME", "https://google.com")
---> 015: driver.Get("https://google.com/")
016: MsgBox,driver.Window.Title "
" driver.Url
017: Return
018: Exit
019: Exit
019: Exit

Continue running the script?
---------------------------
Oui Non
---------------------------
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 16:12

013: driver := ComObjCreate("Selenium.ChromeDriver")
014: drive.start("CHROME", "https://google.com")

Use:

Code: Select all

driver := ComObjCreate("Selenium.ChromeDriver")
driver.Get("https://google.com")
HTH
Mike__
Posts: 11
Joined: 25 Jul 2018, 14:36

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 17:47

Still not working and getting this error:

Code: Select all


---------------------------
test.ahk
---------------------------
Error:  0xA00A0021 - 
Source:		Selenium
Description:	SessionNotCreatedError
session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"E591AB90FD0D03228349A3AFFC68C33E","isDefault":true},"id":1,"name":"","origin":"://"}
  (Session info: chrome=MYIP)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
HelpFile:		(null)
HelpContext:	0

Specifically: Get

	Line#
	003: SendMode,Input
	004: SetWorkingDir,%A_ScriptDir%
	012: Return
	015: driver := ComObjCreate("Selenium.ChromeDriver")
--->	016: driver.Get("https://google.com")  
	017: MsgBox,driver.Window.Title "
" driver.Url
	018: Return
	019: Exit
	020: Exit
	020: Exit

Continue running the script?
---------------------------
Oui   Non   
---------------------------


gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 17:49

It's only a guess, but I think you will still have to "start" - but you had a typo: driver.start("CHROME", "https://google.com") - a missing r
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 19:00

I am new to this but I get the following error... what's wrong? Windows 7, lastest chrome driver and chrome.
I see you didnt mention installing selenium.

Make sure you have installed selenium from here:
https://github.com/florentbr/SeleniumBa ... g/v2.0.9.0

Once Selenium is installed take the newer downloaded chromedriver you have and put it in the selenium folder and overwrite the older chromedriver that comes with it.

For reference chromedriver download page: https://sites.google.com/a/chromium.org ... /downloads
Mike__
Posts: 11
Joined: 25 Jul 2018, 14:36

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 19:38

Hi Thanks it works now. Chrome driver was not in the good folder... used the startup folder instead of the real folder of selenium...

I have 2 more questions
How I could keep my cookies and login access to website in Selenium Chrome?
How I can add an extension and keep it to Selenium Chrome?

Thanks for help :)
Mike__
Posts: 11
Joined: 25 Jul 2018, 14:36

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 20:04

Ok found out that I needed to login 1 time with selenium then it will save on my user profile. :)

However, it look like if I'm signed by google gmail I lost my connection with the website when new selenium chrome open and have to hit the sign in by google to make me logged in again.
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 20:23

Take a look at this post if you want to connect to an existing chrome browsing session:
https://autohotkey.com/boards/viewtopic ... m&start=30
Mike__
Posts: 11
Joined: 25 Jul 2018, 14:36

Re: Using Selenium with AutoHotkey- Cross browser automation!

01 Aug 2018, 23:01

Nice, work perfectly!

If I want to tick a tick box should I use the below?

driver.FindElementByXPath("/html/body/div[26]/div/div[1]/div[2]/div[2]/table/tbody/tr[4]/td[2]").click()


I have other xpath like //*[@id=""THISISATESTVALUE""] that work for selecting with a .click() but the above xpath is the only 1 I have for the "check box" that I need to tick.

I tried with the .click() but it does not work.
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

02 Aug 2018, 01:49

Use FindElementsByXPath (notice the s in the name)

Try:
driver.FindElementsByXPath("/html/body/div[26]/div/div[1]/div[2]/div[2]/table/tbody/tr[4]/td").Item[2]click()

Using absolute paths is ok and will work only if the page layout is the same 100% of the time.
It is worth learning how to write relative paths to be reliable when page layouts change.

HTH
Mike__
Posts: 11
Joined: 25 Jul 2018, 14:36

Re: Using Selenium with AutoHotkey- Cross browser automation!

02 Aug 2018, 21:11

Thanks again:)

Let says the script write something in a text box, how I can add an if statement to verify if that textbox got the input the script entered?

Code: Select all

driver.FindElementByXPath("//div[@data-widget-cid=""widget-16""]/select").SendKeys("Test123")
if (driver.FindElementByXPath("//div[@data-widget-cid=""widget-16""]/select"). ;contain the word Test123 continue, else popup a message box
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

02 Aug 2018, 22:17

Try one of these:
if (driver.FindElementByXPath("//div[@data-widget-cid='widget-16']/select").Attribute("textContent") = "Test123")
if (driver.FindElementByXPath("//div[@data-widget-cid='widget-16']/select").Attribute("innerText") = "Test123")
Mike__
Posts: 11
Joined: 25 Jul 2018, 14:36

Re: Using Selenium with AutoHotkey- Cross browser automation!

03 Aug 2018, 11:20

both not working. No error from script but it not find the word.
CH HAN
Posts: 31
Joined: 18 Sep 2017, 02:16
Contact:

Re: Using Selenium with AutoHotkey- Cross browser automation!

03 Aug 2018, 18:19

Hi,

Does anyone know that ways to get control new tabs? I want to use and navigate new tabs but I don't know how to do that. I googled but I can only find results about java, python and others which not fit for autohotkey. Using driver.getWindowHandles() and driver.switchTo().window(tabs.get(0)) are the soulutions of this problem I think, but I don't know how to change this codes for autohotkey.

https://www.testingexcellence.com/webdr ... avascript/

Code: Select all

driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("http://www.google.com")

MsgBox

driver.sendKeys(driver.Keys.CONTROL)
driver.sendKeys(driver.Keys.SHIFT)
			
Xpath = //*[contains(text(), 'Gmail')]
driver.FindElementByXPath(Xpath).click()

/*
; I don't know how to get a control of the second new tab
driver.getWindowHandles()
driver.switchTo().window(tabs.get(0))
*/

MsgBox

driver.Get("http://the-automator.com/") ; I want to open this url at the second tab(new tab)

MsgBox
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

07 Aug 2018, 08:48

Code: Select all

#Persistent
driver := ComObjCreate("Selenium.ChromeDriver")
driver.Get("http://www.google.com")
driver.ExecuteScript("window.open();")
driver.SwitchToNextWindow
driver.Get("http://www.google.com")
CH HAN
Posts: 31
Joined: 18 Sep 2017, 02:16
Contact:

Re: Using Selenium with AutoHotkey- Cross browser automation!

14 Aug 2018, 16:30

malcev wrote:

Code: Select all

#Persistent
driver := ComObjCreate("Selenium.ChromeDriver")
driver.Get("http://www.google.com")
driver.ExecuteScript("window.open();")
driver.SwitchToNextWindow
driver.Get("http://www.google.com")

It works!! Thank you!! :bravo:
User avatar
Thoughtfu1Tux
Posts: 125
Joined: 31 May 2018, 23:26

Re: Using Selenium with AutoHotkey- Cross browser automation!

10 Oct 2018, 16:10

Anyone have any idea on how to incorporate the new Firefox Marionette Driver into Selenium?

I found a tutorial that links to the new driver that you have to put into the Selenium Folder but am having no luck trying to convert the Java code to AutoHotKey code.
Here is the link to the article that explains the New Firefox driver: Solving Firefox 47+ Selenium WebDriver problem

I have tried the below with no luck.

Code: Select all

driver.setProperty("webdriver.gecko.driver", "C:\Program Files\SeleniumBasic\geckodriver.exe")
driver:= ComObjCreate("Selenium.firefoxDriver") ;Firefox driver

AND

driver.setProperty("webdriver.gecko.driver", "C:\Program Files\SeleniumBasic\geckodriver.exe")
driver:= ComObjCreate("Selenium.geckoDriver") ;Firefox driver

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

10 Oct 2018, 18:41

https://github.com/mozilla/geckodriver/ ... CHANGES.md
0.16.0 (2017-04-21)
Note that geckodriver v0.16.0 is only compatible with Selenium 3.4 and greater.
The version used in this thread https://florentbr.github.io/SeleniumBasic/ is based on Selenium 2.x
User avatar
Thoughtfu1Tux
Posts: 125
Joined: 31 May 2018, 23:26

Re: Using Selenium with AutoHotkey- Cross browser automation!

11 Oct 2018, 14:21

Xtra wrote:https://github.com/mozilla/geckodriver/ ... CHANGES.md
0.16.0 (2017-04-21)
Note that geckodriver v0.16.0 is only compatible with Selenium 3.4 and greater.
The version used in this thread https://florentbr.github.io/SeleniumBasic/ is based on Selenium 2.x
Ah, I totally missed that. Thank you.

Have you tried using AutoHotKey with Selenium 3.x by any chance?
From what I've read there was a big change from SeleniumBasic to Selenium 3, and I haven't seen any posts about anyone using AutoHotKey to control Selenium 3. Is it impossible to control Selenium 3, or has no one really needed to because SeleniumBasic functions without any real issues?

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 29 guests