ComObjCreate Selenium

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
The_Wildry_Dude
Posts: 11
Joined: 17 Aug 2015, 17:15

ComObjCreate Selenium

15 Dec 2015, 20:30

Hey all,

Just playing around and saw the selenium project. Got it up and running with VBA just as test, and it works well. I could be wrong, but this project appears to be a COM object...?

I tried this, with no success:

Code: Select all

selDriver := ComObjCreate("SeleniumWrapper.WebDriver")

selDriver.Start("chrome", "http://www.google.ca")
sleep 4000
selDriver.Open("www.google.ca")
selDriver.Type("name=q", "Eiffel Tower")
selDriver.Click("name=btnG")

selDriver.stop
That code errors out line 1. However when I try the following, it does open a new chrome browser however the URL entered is: data:,

Code: Select all

selDriver := ComObjCreate("{0277FC34-FD1B-4616-BB19-5D556733E8C9}") ; Found this in the registry, not sure if I'm doing this correctly

selDriver.Start("chrome", "http://www.google.ca")
sleep 4000
selDriver.Open("www.google.ca")
selDriver.Type("name=q", "Eiffel Tower")
selDriver.Click("name=btnG")

selDriver.stop
Thanks everyone :)
User avatar
TheDewd
Posts: 1507
Joined: 19 Dec 2013, 11:16
Location: USA

Re: ComObjCreate Selenium

16 Dec 2015, 16:00

Here's an example for Internet Explorer:

Code: Select all

#SingleInstance, Force
#Persistent

driver := ComObjCreate("Selenium.IEDriver")
driver.Get("http://www.google.com/")
driver.findElementById("lst-ib").sendKeys("Eiffel tower")
driver.FindElementByName("btnG").Click
and Firefox:

Code: Select all

#SingleInstance, Force
#Persistent

driver := ComObjCreate("Selenium.FirefoxDriver")
driver.Get("http://www.google.ca/")
driver.findElementById("lst-ib").sendKeys("Eiffel tower")
driver.FindElementByName("btnG").Click
Hopefully you get the idea... :-)
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: ComObjCreate Selenium

22 Dec 2015, 21:12

How are you accessing the Selenium object? (I.e., did you register a dll? Have Selenium installed, etc.
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: ComObjCreate Selenium

26 May 2016, 09:25

Can somebody tell how to use it with autohotkey?
What I have to download and install?
Please!
sjlee128
Posts: 2
Joined: 05 Jun 2016, 03:39

Re: ComObjCreate Selenium

05 Jun 2016, 04:24

Code: Select all

#Persistent

driver:= ComObjCreate("Selenium.IEDriver")
url:="https://www.google.co.kr/search?q=ahk&source=lnms&tbm=isch&sa=X"
driver.Get(url)
loop {
	sleep 100
	if driver.FindElementsByCss(input[name=q]).Count
		break
}
q:=driver.FindElementsByCss(input[name=q])
msgbox % q.Count
q[1].sendKeys(" rocks!")
return

OnExit:
driver.quit()
ExitApp
The code works fine until the msgbox and it prints out "2" because there are 2 query input boxes (one is hidden) on the google image search page
The problem however occurs right on the next line

A quick debugging showed that "object q" is an _WebElements object with guid {0277FC34-FD1B-4616-BB19-7C9763568492}
so I looked it up at
https://github.com/florentbr/SeleniumBa ... lements.cs

[DispId(0), Description("Get the WebElement at the provided index (One-based)")]
WebElement this[int index] { get; }

so there is nothing wrong with the code
I even tried q.this[1] and still the same error
my best guess is that it does not recognize 1 as an integer since variables in ahk don't seem to resolve to a certain type

HELP ME PLEASE!!
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: ComObjCreate Selenium

05 Jun 2016, 11:17

What do You want to do?
If You want loop through elements with css, You can do it like this:

Code: Select all

driver:= ComObjCreate("Selenium.IEDriver")
url:="https://www.google.co.kr/search?q=ahk&source=lnms&tbm=isch&sa=X"
driver.Get(url)
For k in driver.findElementsByCss("input[name=""q""]")
{
   if k.IsDisplayed
      k.SendKeys(" rocks!")
   msgbox % A_Index
}
msgbox Done
driver.quit()
ExitApp
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: ComObjCreate Selenium

05 Jun 2016, 14:02

Can someone explain to me what you downloaded and "installed" / Registered?
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: ComObjCreate Selenium

05 Jun 2016, 16:44

Thank you malcev! I started playing with it and have had some decent luck! I look forward ti digging deeper! :)
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Re: ComObjCreate Selenium

08 Jun 2016, 15:07

Hello,

I was really curious whether it's possible to attach Selenium to a running browser instance, in my case Firefox. Want to use it as a sort of MozRepl. The main answer (no) can be found here: Allow webdriver to attach to a running browser · Issue #18 · SeleniumHQ/selenium-google-code-issue-archive · GitHub. But there are some hints that it is possible (e. g. stackoverflow, binaryclips, binaryclips).


Greetings
hotkeyguy
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: ComObjCreate Selenium

08 Jun 2016, 17:40

I've been playing with the Selenium object over the past couple of days. I've figured out many ways to do much of what we do with COM (but it wasn't as intuitive and also there are lots of different types of syntax which is confusing). I'll probably share some of it early next week.

@HotkeyGuy- I agree it would be great to be able to connect to an existing browser but haven't figured that one out yet! I figured at a minimum I could just have my script launch the browser thru Selenium that way, whatever I happened to be doing, it would already be connected to the object.
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
enter8
Posts: 102
Joined: 05 May 2016, 16:48

Re: ComObjCreate Selenium

15 Jan 2017, 17:46

My apologies for bumping this old thread, but could someone do a getElementsByClassname in selenium? Everything up to the getelement works, but I can't seem to assign the result to a variable.

Code: Select all

driver := ComObjCreate("Selenium.FirefoxDriver")
driver.Get("http://www.worldslongestwebsite.com/")
sleep 1500
var1 := driver.getElementsByClassName("footer")[0].innerHTML
msgbox % var1
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: ComObjCreate Selenium

16 Jan 2017, 09:21

Try this
var:=driver.findElementByClass("footer").Attribute("value") ;change "value" to things like OuterHTML, Text, InnerText etc.
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
enter8
Posts: 102
Joined: 05 May 2016, 16:48

Re: ComObjCreate Selenium

16 Jan 2017, 13:37

Joe Glines wrote:Try this
var:=driver.findElementByClass("footer").Attribute("value") ;change "value" to things like OuterHTML, Text, InnerText etc.
So I can't use my browser console-friendly javascript with selenium? That's a bummer. For what it is, it's still pretty nifty, but... I have a hard enough time getting elements via JS, so figuring out something entirely new is a bit daunting.
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: ComObjCreate Selenium

17 Jan 2017, 14:12

You can still use it however adapting it to Selenium format is not as straight-forward.
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: ComObjCreate Selenium

29 May 2017, 17:32

In case you didn't see it I posted a bunch of tutorial videos on using Selenium with AutoHotkey
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 118 guests