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: 1204
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] [Download] GeSHi © Codebox Plus

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] [Expand] [Download] GeSHi © Codebox Plus

User avatar
gregster
Posts: 1379
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: 1204
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: 1204
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: 1204
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] [Download] GeSHi © Codebox Plus

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: 1204
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
GitHub: MagnaPax

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] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus

malcev
Posts: 92
Joined: 12 Aug 2014, 12:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

07 Aug 2018, 08:48

Code: [Select all] [Download] GeSHi © Codebox Plus

#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
GitHub: MagnaPax

Re: Using Selenium with AutoHotkey- Cross browser automation!

14 Aug 2018, 16:30

malcev wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

#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:

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 1 guest