Using Selenium with AutoHotkey- Cross browser automation!

Helpful script writing tricks and HowTo's
User avatar
Xtra
Posts: 879
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

19 Sep 2017, 23:41

You could very easily set the user & pass elements and click the login button.
Logging into a site is no different than automating anything else on a website.
By doing this you wont have to rely on cookies which will eventually expire. Just a thought.
User avatar
Joe Glines
Posts: 470
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Using Selenium with AutoHotkey- Cross browser automation!

20 Sep 2017, 07:19

Try this:
After the Selenium version of Chrome loads, use the same process you did for your regular chrome executable to get the path of the current profile (put "chrome://version/" in the url). Take a look at the "Profile Path" that it is using. Is it what you've defined in your script?

If it is, use explorer to navigate to that folder and verify you have a "cookies" file. When I opened mine I can find LinkedIn.com (which is what i'd logged into for testing of this)
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

24 Sep 2017, 23:09

Joe Glines / It works! I copied and used profile path after had created Chrome window by Selenium. The profile paths of Chrome opened by manually and Selenium are different. Thank you!

Xtra / Your code also works! Thank you!
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

28 Oct 2017, 19:09

seleniumError.jpg
(567.72 KiB) Not downloaded yet
Hi, I've tried to login a webpage but I couldn't. I think it's because of the class name of a blank which I want to put in my login ID. it has spaces between letters of it. The class name is 'ng-pristine ng-invalid ng-touched' And my code is like this

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

driver.executeScript("arguments[0].setAttribute('value', 'abcd')", driver.findElementsByClass("ng-pristine ng-invalid ng-touched"))

AHK pops up an error message that InvalidSelectorError, I attached a screen shot file of that. I don't know how I can handle it.
User avatar
Xtra
Posts: 879
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

28 Oct 2017, 19:38

You can always use Xpath or CSS

Xpath working Example (minus real creds edit to your own)

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

driver.FindElementByXPath("/html/body/fg-root/div[1]/fg-public-layout/fg-auth/div[1]/div/div/div[1]/div/div/form/div[1]/input").SendKeys("abcd")    ; Username
driver.FindElementByXPath("/html/body/fg-root/div[1]/fg-public-layout/fg-auth/div[1]/div/div/div[1]/div/div/form/div[2]/input").SendKeys("1234") ; Password
driver.FindElementByXPath("/html/body/fg-root/div[1]/fg-public-layout/fg-auth/div[1]/div/div/div[1]/div/div/form/div[4]/button").click() ; Button


HTH
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

29 Oct 2017, 22:15

Gosh, it works. I didn't know about Xpath. Thank you!!!! :bravo:
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

29 Oct 2017, 22:34

Hi,

Anybody knows how to keep browser open after end of calling function? I have made some codes using Selenium in a function, and I call it from main.ahk file. I want to keep the browser which I use in the function after end of calling the function but it closes automatically when the function is closed. I've googled about this and many people suggested that using sleep(900000), but I can't use that because I want to process other task while the used browser opened. Anybody has any solution about it? And can i reuse the browser in other function? Thank you.
User avatar
Xtra
Posts: 879
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

30 Oct 2017, 01:33

Put this at top of the script: (Autoexec section)

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

Global driver
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

31 Oct 2017, 00:46

It's simple. I'll try that. Thank you. But I still don't know the way to leave a browser opened after end of scripts. I should know that first to reuse the browser. :crazy:
tmplinshi
Posts: 1091
Joined: 01 Oct 2013, 14:57

Re: Using Selenium with AutoHotkey- Cross browser automation!

09 Nov 2017, 03:46

Nice tutorial!

I want to add a useful tips here:

Connect to existing Chrome window just like WBGet()!

Step 1. Start Chrome with command line: chrome.exe --remote-debugging-port=9222
(Be sure to kill all running Chome windows that didn't start with --remote-debugging-port=9222)

Step 2. Open some webpages manually, then run the following code:

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



:beer:
Last edited by tmplinshi on 09 Nov 2017, 04:51, edited 1 time in total.
User avatar
Xtra
Posts: 879
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

09 Nov 2017, 04:19

@tmplinshi Thanks! That should fix the one thing i didnt like about selenium.
User avatar
Joe Glines
Posts: 470
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Using Selenium with AutoHotkey- Cross browser automation!

09 Nov 2017, 06:29

@tmplinshi- Great work!!! I tested this and was able to get it to connect to an open Chrome window. Having said that the second part of your code (under F12 hotkey) doesn't work for me but I swapped it with the following and it worked fine. :)

Any idea on how to do this with FireFox and/or IE?

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

F12::
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("http://the-automator.com/")
MsgBox, % driver.Window.Title "`n" driver.Url
return
User avatar
hoppfrosch
Posts: 300
Joined: 07 Oct 2013, 04:05
GitHub: hoppfrosch
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Using Selenium with AutoHotkey- Cross browser automation!

09 Nov 2017, 09:29

Joe Glines wrote:Any idea on how to do this with FireFox and/or IE?

For Firefox we might be able to use the same mechanism via remote debugging port .... see: https://developer.mozilla.org/en-US/doc ... erver_port

Haven't tested it!
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

11 Nov 2017, 16:01

Wow! Now I can use an existing browser and leave it opened after end of codes. Thank you!!

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus

CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

11 Nov 2017, 16:54

Hi,

I want to click mouse right button on a element of a web page to select one of menu, so I googled and visited many pages, but almost solution was coded by Java, but because I don't know other computer languages I couldn't get it. I tried some codes, but it was not working.

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

	driver.FindElementByXPath("//*[@id="contents-body"]/div/div[2]/table/tbody/tr[8]/td[2]/a").contextClick().build().perform()
; driver.FindElementByXPath("//*[@id="contents-body"]/div/div[2]/table/tbody/tr[8]/td[2]/a").rightclick()


I think the answer is on a web page below at a section "13. Context Click (Right Click)", but I can't apply it to AHK

http://seleniumhome.blogspot.com/2013/1 ... -code.html
Last edited by CH HAN on 11 Nov 2017, 17:15, edited 3 times in total.
User avatar
Xtra
Posts: 879
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

11 Nov 2017, 16:56

@ CH HAN You can combine your 2 SendKeys lines into one like this:

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

driver.findElementsByName("s").item[1].SendKeys("hello world").SendKeys(driver.Keys.ENTER)
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

11 Nov 2017, 17:10

@ Xtra
Thank you for quick answer. Your code is good. It can help me save code, but I want to 'CLICK' mouse right button on a specific element of a web page :)

And there is another problem (I changed my code above of my post while you uploaded your post.) which an error message is that The following variable name contains an illegal character: "body""

I added ` before " but it's not working.
User avatar
Xtra
Posts: 879
Joined: 02 Oct 2015, 12:15

Re: Using Selenium with AutoHotkey- Cross browser automation!

11 Nov 2017, 17:48

Use single quotes for xpath id like this:

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

"//*[@id='contents-body']"
CH HAN
Posts: 13
Joined: 18 Sep 2017, 02:16

Re: Using Selenium with AutoHotkey- Cross browser automation!

12 Nov 2017, 04:00

@ Xtra
Thank you, but it's not working...

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 5 guests