Using Selenium with AutoHotkey- Cross browser automation!

Helpful script writing tricks and HowTo's
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

25 Oct 2019, 13:16

@malcev, thanks for the clarification.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

25 Oct 2019, 13:37

Thanks, malcev. As others have complained of on StackOverflow, the supplied SeleniumBasic.chm file is corrupt. I didn't see any other API documentation in the folder.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

25 Oct 2019, 13:52

Strange. For me this file works on both systems: Win7 and Win10.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

25 Oct 2019, 14:00

Perhaps it's a question of encoding. I haven't tried with Win10 yet, but I will. Might I ask what codepage your system is?
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

25 Oct 2019, 14:07

IsSingleByte : True
BodyName : koi8-r
EncodingName : Cyrillic (Windows)
HeaderName : windows-1251
WebName : windows-1251
WindowsCodePage : 1251
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : True
IsMailNewsSave : True
EncoderFallback : System.Text.InternalEncoderBestFitFallback
DecoderFallback : System.Text.InternalDecoderBestFitFallback
IsReadOnly : True
CodePage : 1251
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

25 Oct 2019, 14:14

Большое спасибо! As it turns out, I was able to open it from the command prompt with

Code: Select all

C:\temp> hh Selenium.chm
I don't recall this happening before, that I had to do that, that is. Double-clicking a *.chm file generally opens the file for me. At any rate, thanks again, and the mystery is solved! And the file is very helpful indeed.
Regards,
burque505
daiweisc
Posts: 46
Joined: 19 Oct 2019, 04:27

Re: Using Selenium with AutoHotkey- Cross browser automation!

26 Oct 2019, 04:46

malcev wrote:
25 Oct 2019, 05:52
@gregster, did You ever use selenium wrapper for vba? And if Yes, where did You find this methods: AddExperimentalOption, ChromeOptions?
@daiweisc, preferences You can set with WebDriver.SetPreference Method.
@gregster, thank your reply soon, i will try it on Monday.
@malcev, thank your conclusion, i think it will be simple for use, but i am confused with WebDriver.SetPreference and WebDriver.AddArgument? what is the difference of WebDriver.SetPreference and WebDriver.AddArgument?
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: Using Selenium with AutoHotkey- Cross browser automation!

26 Oct 2019, 14:14

hi, can Selenium be accessed only from Debug mode browser, or can I access the page from the active browser, usin Selenium, no mater what?
daiweisc
Posts: 46
Joined: 19 Oct 2019, 04:27

Re: Using Selenium with AutoHotkey- Cross browser automation!

26 Oct 2019, 19:18

malcev wrote:
26 Oct 2019, 05:27
Preferences:
https chromium.googlesource.com /chromium/src/+/master/chrome/common/pref_names.cc Broken Link for safety
Arguments:
https chromium.googlesource.com /chromium/src/+/master/chrome/common/chrome_switches.cc Broken Link for safety
in Edge and Firefox ,I want to use the function of "ask where to save each file before downloading", just like Chrome code :

Code: Select all

prefs := """download.prompt_for_download"": True"		; or prefs := "'download.prompt_for_download': True"
options.AddExperimentalOption("prefs", prefs)
How to write the code in Edge and Firefox ?
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

27 Oct 2019, 05:37

@euras, read this topic from the start.
@daiweisc,
1) Code that You provided will not work.
2) Boolean value true in Com is not just "true" or 1, but ComObject(0xB, -1).
3) You can search for Edge and Firefox preferences by Yourself.
daiweisc
Posts: 46
Joined: 19 Oct 2019, 04:27

Re: Using Selenium with AutoHotkey- Cross browser automation!

28 Oct 2019, 02:07

malcev wrote:
27 Oct 2019, 05:37
@euras, read this topic from the start.
@daiweisc,
1) Code that You provided will not work.
2) Boolean value true in Com is not just "true" or 1, but ComObject(0xB, -1).
3) You can search for Edge and Firefox preferences by Yourself.
thanks, i run this code works well

Code: Select all

Driver := ComObjCreate("Selenium.ChromeDriver")           ; Start with Chrome
Driver.SetPreference("download.prompt_for_download", ComObject(0xB, -1))
Driver.AddArgument("--start-maximized")
daiweisc
Posts: 46
Joined: 19 Oct 2019, 04:27

Re: Using Selenium with AutoHotkey- Cross browser automation!

28 Oct 2019, 22:05

i automate the web hover menu with selenium.
the code is :

Code: Select all

Driver.FindElementByCSS("#divMenu > ul > li:nth-child(7) > a").ClickAndHold()
Sleep,500
Driver.FindElementByCSS("#divMenu > ul > li:nth-child(7) > ul > li:nth-child(1) > a").Click()
Sleep,1000
sometimes the code does work, sometimes works wrong. this make me confused. Who can help me?
the wrong is missing element.
daiweisc
Posts: 46
Joined: 19 Oct 2019, 04:27

Re: Using Selenium with AutoHotkey- Cross browser automation!

29 Oct 2019, 03:14

Sir Teddy the First wrote:
06 Oct 2019, 03:05
@Xtra
I'm using Microsoft Edge (EdgeHTML) version 18 and thats the problem because you can only download the drivers up to version 17, version 18 needs to be installed through the command window so I don't get an .exe-file that I could copy to the SeleniumBasic Folder.
That is my problem.

I already tried downloading the version 17 file. The .exe-file can be started without a problem but when trying to access that driver via AHK I still get a timeout message.
I can not use Edge well,how do you access the driver via AHK. I downloads the Edge WebDriver and copy it to the SeleniumBasic Folder. But it does not work.
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Using Selenium with AutoHotkey- Cross browser automation!

11 Nov 2019, 02:10

Code: Select all

<a href="javascript:void(0)" data-id="26b60b16-f60b-4ea0-b439-2bbc5bd6dc08" data-what="getEgmPlakaQ" class="btn btn-dark"><i class="fa fa-spinner" aria-hidden="true"></i> Detail</a>
I would like to click the button named "Detail" in the html code above. but the following code doesn't work.
I use selenium. Can you help me. Thank you.

Code: Select all

driver.executeScript("return document.all('26b60b16-f60b-4ea0-b439-2bbc5bd6dc08').click()")
this code does not work. somehow failed!


https://imgyukle.com/i/ekran-alintisi.Ew2qoH

Can you help me. Thank you.
blue83
Posts: 157
Joined: 11 Apr 2018, 06:38

Re: Using Selenium with AutoHotkey- Cross browser automation!

22 Nov 2019, 08:42

Hi why is there need for .NET Framework 3.5?

I have 4.0 and above, and no admin rights for instalation, how to solve this?
robo_z
Posts: 6
Joined: 21 Nov 2015, 15:54

Re: Using Selenium with AutoHotkey- Cross browser automation!

31 Mar 2020, 17:52

How to Translate this:


Select oSelect = new Select(driver.findElement(By.id("yy_date_8")));

oSelect.selectByVisibleText("2010");


to autohotkey to use with Selenium.

this code is for select a element from a listview

Thanks.
Last edited by robo_z on 31 Mar 2020, 18:43, edited 1 time in total.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

31 Mar 2020, 18:35

Search doc for asselect method.
User avatar
Thoughtfu1Tux
Posts: 125
Joined: 31 May 2018, 23:26

Re: Using Selenium with AutoHotkey- Cross browser automation!

18 Jun 2020, 01:56

I was playing around with burque505's PDF code that he posted in 2019 and managed to dig up a way to take a screenshot of the page thanks to this wonderful StackOverflow answer: https://stackoverflow.com/questions/60992134/seleniumbasic-vba-takescreenshot-element-outside-of-the-screenshot-error?r=SearchResults

Code: Select all


driver:= ComObjCreate("Selenium.CHROMEDriver") ;Select and Create Chrome driver instance
driver.setbinary("C:\Software\Chromium\chrome.exe")	;Sets path to custom Binary

driver.AddArgument("disable-infobars") ;Hides 'Chrome is being controlled by automated test software' message
driver.AddArgument("--start-maximized") ; Maximize Chrome Browser
driver.AddArgument("--disable-gpu")
;driver.AddArgument("--headless")
driver.get("https://www.startpage.com")
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
;driver.Window.Maximize	; Maximize the window, not really necessary as chrome starts that way by default


savepath = C:\Users\%A_UserName%\Downloads\StartpageScreenshot.png
driver.TakeScreenshot().SaveAs(savepath)

run, %savepath%	; Open screenshot
Msgbox, Screenshot taken!

ExitApp

burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Using Selenium with AutoHotkey- Cross browser automation!

18 Jun 2020, 13:22

Thanks, @Thoughtfu1Tux! Here's a version using SChrome_Get by @AHK_User with credits to @tmplinshi, @CH HAN and @Joe Glines.

Code: Select all

#Include SChrome_Get.ahk

driver := SChrome_Get("https://chromium.woolyss.com/")
driver.AddArgument("disable-infobars") ;Hides 'Chrome is being controlled by automated test software' message
driver.AddArgument("--start-maximized") ; Maximize Chrome Browser
driver.AddArgument("--disable-gpu")
;driver.AddArgument("--headless")

driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
;driver.Window.Maximize	; Maximize the window, not really necessary as chrome starts that way by default

savepath = %A_ScriptDir%\ChromiumScreenshot.png
driver.TakeScreenshot().SaveAs(savepath)

run, %savepath%	; Open screenshot
Msgbox, Screenshot taken!

ExitApp
EDIT: Seems to work fine like this as well.

Code: Select all

#Include SChrome_Get.ahk
driver := SChrome_Get("https://chromium.woolyss.com/")
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
;driver.Window.Maximize	; Maximize the window, not really necessary as chrome starts that way by default
savepath = %A_ScriptDir%\ChromiumScreenshot.png
driver.TakeScreenshot().SaveAs(savepath)
run, %savepath%	; Open screenshot
Msgbox, Screenshot taken!
ExitApp
RE-EDIT:

This scrolls the nav footer into view before taking the screenshot.

Code: Select all

#Include SChrome_Get.ahk
driver := SChrome_Get("https://www.amazon.com/")
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
driver.FindElementById("navFooter").ScrollIntoView()
;driver.Window.Maximize	; Maximize the window, not really necessary as chrome starts that way by default
savepath = %A_ScriptDir%\ChromiumScreenshot.png
driver.TakeScreenshot().SaveAs(savepath)
run, %savepath%	; Open screenshot
Msgbox, Screenshot taken!
ExitApp
Regards,
burque505

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 43 guests