Page 4 of 5

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 14:30
by Mike__
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
---------------------------

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 16:12
by Xtra
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 17:47
by Mike__
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   
---------------------------



Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 17:49
by gregster
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 19:00
by Xtra
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 19:38
by Mike__
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 :)

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 20:04
by Mike__
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.

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 20:23
by Xtra
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 01 Aug 2018, 23:01
by Mike__
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.

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 02 Aug 2018, 01:49
by Xtra
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 02 Aug 2018, 21:11
by Mike__
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 02 Aug 2018, 22:17
by Xtra
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")

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 03 Aug 2018, 11:20
by Mike__
both not working. No error from script but it not find the word.

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 03 Aug 2018, 13:01
by Xtra

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 03 Aug 2018, 18:19
by CH HAN
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 07 Aug 2018, 08:48
by malcev

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")

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 14 Aug 2018, 16:30
by CH HAN
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:

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 10 Oct 2018, 16:10
by Thoughtfu1Tux
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


Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 10 Oct 2018, 18:41
by Xtra
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

Re: Using Selenium with AutoHotkey- Cross browser automation!

Posted: 11 Oct 2018, 14:21
by Thoughtfu1Tux
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?