Using Selenium with AutoHotkey- Cross browser automation!
- Joe Glines
- Posts: 771
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
I'm curious if this will affect Selnium & ahk use
Google will lock down chrome on Windows
Google will lock down chrome on Windows
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Using Selenium with AutoHotkey- Cross browser automation!
Hi,
I've figured out a way to use Xpaths including ""(quotation-marks).
If you want to make your own customized Xpaths, you should check a video below.
https://youtu.be/3uktjWgKrtI
I've figured out a way to use Xpaths including ""(quotation-marks).
Code: Select all
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("https://www.google.com/")
; Put a keyword 'AutoHotkey' in a blank
Xpath = //*[@id="lst-ib"]
driver.FindElementByXPath(Xpath).SendKeys("AutoHotkey")
driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.Enter)
MsgBox
; Open AutoHotkey web page
Xpath = //*[@id="rso"]/div[1]/div/div/div/div/h3/a
driver.FindElementByXPath(Xpath).click()
MsgBox
https://youtu.be/3uktjWgKrtI
Re: Using Selenium with AutoHotkey- Cross browser automation!
Code: Select all
wb := IEGet("My Drive - Google Drive - Internet Explorer")
; everything is not working
/*
wb.document.getElementsByTagName("SPAN")[84].focus()
Send, {AppsKey}
Send, {Down}
Send, {Down}
Send, {Enter}
*/
;~ wb.document.getElementsByTagName("SPAN")[84].click(Right)
;~ wb.document.getElementsByTagName("SPAN")[84].rightclick()
MsgBox
https://seleniumhome.blogspot.com/2013/ ... -code.html
https://stackoverflow.com/questions/114 ... river-java
Does anybody know any ways to open right-click menu and select one of elements of the menu on Chrome using Selenium~?!?!
- Joe Glines
- Posts: 771
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
I wouldn't try and send mouse-clicks. Are the actions you want taken available from the HTML on the element? Typically they are a you can just trigger the proper event (or load the proper url, etc)
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Using Selenium with AutoHotkey- Cross browser automation!
Code: Select all
#persistent
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("https://www.google.com")
element := driver.FindElementById("lst-ib")
driver.Actions.ClickContext(element).Perform
Re: Using Selenium with AutoHotkey- Cross browser automation!
@malcev
Wow!! it works!! Thank you!! Now I can control Chrome that I want ways, Thank you again!!!!
Wow!! it works!! Thank you!! Now I can control Chrome that I want ways, Thank you again!!!!
Re: Using Selenium with AutoHotkey- Cross browser automation!
If you want to find a specific text on a web page, you can use codes below
Code: Select all
keyword= ; keyword you want to find
Xpath = //*[text() = '%keyword%']
if(driver.FindElementByXPath(Xpath))
driver.FindElementByXPath(Xpath).click()
- Joe Glines
- Posts: 771
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
@CH HAN- thanks for publishing that! I made some minor tweaks and demonstrate it's usage here.
Code: Select all
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("http://the-automator.com")
;********************find and click text***********************************
keyword:="Continue reading" ; keyword you want to find- Note Case sensitive
if(driver.FindElementByXPath("//*[text() = '" keyword "']"))
driver.FindElementByXPath("//*[text() = '" keyword "']").click()
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Using Selenium with AutoHotkey- Cross browser automation!
@ Joe Glines
Thank you. Your code looks more efficient!
Now I'm searching for ways to get all Xpaths and innterTexts which contains a specific word
First Msgbox code line returns only a value which first founded and the 2nd has an error. I'd like to get 2nd, 3rd, and more value which contains the text. Anybody has any ideas?
Thank you. Your code looks more efficient!
Now I'm searching for ways to get all Xpaths and innterTexts which contains a specific word
Code: Select all
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("http://the-automator.com/web-scraping-with-autohotkey/")
keyword:="website"
if(driver.FindElementByXPath("//*[contains(text(), '" keyword "')]"))
MsgBox, % driver.FindElementByXPath("//*[contains(text(), '" keyword "')]").Attribute("innerText")
MsgBox, % driver.FindElementByXPath("//*[contains(text(), '" keyword "')]").item[1].Attribute("innerText")
Last edited by CH HAN on 11 Dec 2017, 00:22, edited 3 times in total.
Re: Using Selenium with AutoHotkey- Cross browser automation!
A code below can help you to use Ctrl+A
Code: Select all
driver.FindElementByXPath(Xpath).sendKeys(driver.Keys.CONTROL, "a") ; Ctrl+A
Re: Using Selenium with AutoHotkey- Cross browser automation!
I've found the answer of the question I posted above, it's using brackets. If you want use elements sharing same Xpath, you should add brackets end of Xpath like (Xpath)[2] or (Xpath)[3]
Code: Select all
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("http://the-automator.com/web-scraping-with-autohotkey/")
keyword:="website"
if(driver.FindElementByXPath("//*[contains(text(), '" keyword "')]"))
{
MsgBox, % driver.FindElementByXPath("(//*[contains(text(), '" keyword "')])").Attribute("innerText")
MsgBox, % driver.FindElementByXPath("(//*[contains(text(), '" keyword "')])[2]").Attribute("innerText")
}
Re: Using Selenium with AutoHotkey- Cross browser automation!
You should check this code to wait for a web page is loaded.
Code: Select all
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads
- Joe Glines
- Posts: 771
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
@CH HAN - Sorry I didn't see your previous question about accessing the other words. yes, adding brackets will access the items as an array. If I remember correctly, in Selenium, they are not zero based (unlike in COM where they are).
Regarding the page loading- Have you had issues with Selenium moving forward before the page fully loaded? In my experimenting I didn't have that issue...
Regarding the page loading- Have you had issues with Selenium moving forward before the page fully loaded? In my experimenting I didn't have that issue...
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Using Selenium with AutoHotkey- Cross browser automation!
@Joe Glines
Sorry for the late reply, I've not touched Selenium for long time. The answer is Yes. Sometimes Selenium just continues codes even while browser is still loading a page so I change the waiting code like the below but it still not works perfectly either.
Sorry for the late reply, I've not touched Selenium for long time. The answer is Yes. Sometimes Selenium just continues codes even while browser is still loading a page so I change the waiting code like the below but it still not works perfectly either.
Code: Select all
driver.executeScript("return document.readyState").toString().equals("complete")
Re: Using Selenium with AutoHotkey- Cross browser automation!
Set defaults of Chrome browser
However, these are not working for Chrome browsers controlled by ChromeGet() function.
Code: Select all
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.AddArgument("disable-infobars") ; Close Message that 'Chrome is being controlled by automated test software'
driver.AddArgument("--start-maximized") ; Maximize Chrome Browser
driver.Get("http://duckduckgo.com/")
driver.ExecuteScript("document.body.style.zoom = '100%';") ; Set the font of Chrome browser to 100%
- Joe Glines
- Posts: 771
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
Just curious if anyone on this thread has tried GeekDude's solution for automating Chrome w/o Selenium. I worked on some functions to use with it for setting/getting data but haven't had time to finish them up and share.
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Using Selenium with AutoHotkey- Cross browser automation!
Thank you for the tutorials.
How do I hide the chrome window? Thanks.
How do I hide the chrome window? Thanks.
- Joe Glines
- Posts: 771
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
That you can probably do with just a standard WinMinimize command https://autohotkey.com/docs/commands/WinMinimize.htm
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Using Selenium with AutoHotkey- Cross browser automation!
http://chromedriver.chromium.org/capabilitiesflatwater wrote:How do I hide the chrome window?
Tried with driver.SetCapability("args", "['headless']") but didn't work. Anyway, below are two ways that worked:
Method 1: Using --headless
Code: Select all
Run, chrome.exe --remote-debugging-port=9222 --headless --disable-gpu --disable-extensions,,, pid
driver := ComObjCreate("Selenium.ChromeDriver")
driver.SetCapability("debuggerAddress", "127.0.0.1:9222")
driver.Get("https://www.bing.com")
MsgBox, % driver.Title
Process, Close, %pid%
Code: Select all
driver := ComObjCreate("Selenium.PhantomJSDriver")
driver.Get("https://www.bing.com")
MsgBox, % driver.Title
Re: Using Selenium with AutoHotkey- Cross browser automation!
Thank you very much. I used the first method.tmplinshi wrote:http://chromedriver.chromium.org/capabilitiesflatwater wrote:How do I hide the chrome window?
Tried with driver.SetCapability("args", "['headless']") but didn't work. Anyway, below are two ways that worked:
Method 1: Using --headlessMethod 2: Using PhantomJSCode: Select all
Run, chrome.exe --remote-debugging-port=9222 --headless --disable-gpu --disable-extensions,,, pid driver := ComObjCreate("Selenium.ChromeDriver") driver.SetCapability("debuggerAddress", "127.0.0.1:9222") driver.Get("https://www.bing.com") MsgBox, % driver.Title Process, Close, %pid%
Code: Select all
driver := ComObjCreate("Selenium.PhantomJSDriver") driver.Get("https://www.bing.com") MsgBox, % driver.Title