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.
Using Selenium with AutoHotkey- Cross browser automation!
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
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)
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)
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 / 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!
Xtra / Your code also works! Thank you!
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
That's great!
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
driver.executeScript("arguments[0].setAttribute('value', 'abcd')", driver.findElementsByClass("ng-pristine ng-invalid ng-touched"))
Re: Using Selenium with AutoHotkey- Cross browser automation!
You can always use Xpath or CSS
Xpath working Example (minus real creds edit to your own)
HTH
Xpath working Example (minus real creds edit to your own)
Code: Select all
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
Re: Using Selenium with AutoHotkey- Cross browser automation!
Gosh, it works. I didn't know about Xpath. Thank you!!!!
Re: Using Selenium with AutoHotkey- Cross browser automation!
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.
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.
Re: Using Selenium with AutoHotkey- Cross browser automation!
Put this at top of the script: (Autoexec section)
Code: Select all
Global driver
Re: Using Selenium with AutoHotkey- Cross browser automation!
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.
Re: Using Selenium with AutoHotkey- Cross browser automation!
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:
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
driver := ChromeGet()
MsgBox, % driver.Window.Title "`n" driver.Url
ChromeGet(IP_Port := "127.0.0.1:9222") {
driver := ComObjCreate("Selenium.ChromeDriver")
driver.SetCapability("debuggerAddress", IP_Port)
driver.Start()
return driver
}
F12::
driver.Start()
MsgBox, % driver.Window.Title "`n" driver.Url
return
Last edited by tmplinshi on 09 Nov 2017, 04:51, edited 1 time in total.
Re: Using Selenium with AutoHotkey- Cross browser automation!
@tmplinshi Thanks! That should fix the one thing i didnt like about selenium.
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
@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?
Any idea on how to do this with FireFox and/or IE?
Code: Select all
F12::
driver:= ComObjCreate("Selenium.CHROMEDriver") ;Chrome driver
driver.Get("http://the-automator.com/")
MsgBox, % driver.Window.Title "`n" driver.Url
return
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!
- hoppfrosch
- Posts: 447
- Joined: 07 Oct 2013, 04:05
- Location: Rhine-Maine-Area, Hesse, Germany
- Contact:
Re: Using Selenium with AutoHotkey- Cross browser automation!
For Firefox we might be able to use the same mechanism via remote debugging port .... see: https://developer.mozilla.org/en-US/doc ... erver_portJoe Glines wrote: Any idea on how to do this with FireFox and/or IE?
Haven't tested it!
Re: Using Selenium with AutoHotkey- Cross browser automation!
Wow! Now I can use an existing browser and leave it opened after end of codes. Thank you!!
Code: Select all
UsingAnExistingBrowser()
Exitapp
UsingAnExistingBrowser(){
URL = http://the-automator.com/
run % "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222" ( winExist("ahk_class Chrome_WidgetWin_1") ? " --new-window " : " " ) URL
driver := ChromeGet()
driver.findElementsByName("s").item[1].SendKeys("hello world")
driver.findElementsByName("s").item[1].SendKeys(driver.Keys.ENTER) ;http://seleniumhome.blogspot.com/2013/07/how-to-press-keyboard-in-selenium.html
MsgBox pause
return
}
ChromeGet(IP_Port := "127.0.0.1:9222") {
driver := ComObjCreate("Selenium.ChromeDriver")
driver.SetCapability("debuggerAddress", IP_Port)
driver.Start()
return driver
}
Re: Using Selenium with AutoHotkey- Cross browser automation!
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.
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
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
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()
http://seleniumhome.blogspot.com/2013/1 ... -code.html
Last edited by CH HAN on 11 Nov 2017, 17:15, edited 3 times in total.
Re: Using Selenium with AutoHotkey- Cross browser automation!
@ CH HAN You can combine your 2 SendKeys lines into one like this:
Code: Select all
driver.findElementsByName("s").item[1].SendKeys("hello world").SendKeys(driver.Keys.ENTER)
Re: Using Selenium with AutoHotkey- Cross browser automation!
@ 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.
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.
Re: Using Selenium with AutoHotkey- Cross browser automation!
Use single quotes for xpath id like this:
Code: Select all
"//*[@id='contents-body']"
Re: Using Selenium with AutoHotkey- Cross browser automation!
@ Xtra
Thank you, but it's not working...
Thank you, but it's not working...
Code: Select all
URL = http://the-automator.com/
run % "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222" ( winExist("ahk_class Chrome_WidgetWin_1") ? " --new-window " : " " ) URL
driver := ChromeGet()
; To click 'Web Scraping'
driver.FindElementByXPath("//*[@id='menu-item-1662']/a/span").click()
ChromeGet(IP_Port := "127.0.0.1:9222") {
driver := ComObjCreate("Selenium.ChromeDriver")
driver.SetCapability("debuggerAddress", IP_Port)
driver.Start()
return driver
}