Selenium Chrome - Translating Python Argument into AHK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Thoughtfu1Tux
Posts: 125
Joined: 31 May 2018, 23:26

Selenium Chrome - Translating Python Argument into AHK

Post by Thoughtfu1Tux » 26 Jun 2020, 18:31

Hello, I've been using Selenium with Chrome for a couple of years now and it has been insanely useful. A little while back Chrome was updated and now the newest version shows a "Chrome is being controlled by automated test software" notification whenever i start a new selenium instance. I found a guide on how to disable the notification in other programming languages (https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification), but I have not been able to figure out how to translate this into autohotkey.

Here is my template selenium code that i use in my scripts:

Code: Select all

driver:= ComObjCreate("Selenium.CHROMEDriver") ;Select and Create Chrome driver instance
;driver:= ComObjCreate("Selenium.phantomjsDriver") ;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.google.com")	;Open selected URL
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
Msgbox,
Thank you very much for any help that you can offer!
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Selenium Chrome - Translating Python Argument into AHK

Post by burque505 » 23 Mar 2021, 15:44

@Thoughtfu1Tux, sorry for this late reply. It's late because I hadn't found SeleniumBasic 3.141.0.0 yet. :D
I find Selenium for AHK useful too, and although a lot of websites will detect I'm using Selenium and kick me off, for those that don't many things are just easier than they are with Chrome.ahk.
Here is some sample code for you. If you feel like trying it and run into any installation problems let me know.

Code: Select all

;https://www.autohotkey.com/boards/viewtopic.php?f=7&t=87159
SetBatchLines, -1

wd := ComObjCreate("SeleniumBasic.IWebDriver")
svc := ComObjCreate("SeleniumBasic.FirefoxDriverService")
options := ComObjCreate("SeleniumBasic.FirefoxOptions")

svc.CreateDefaultService.driverPath := "C:\Downloads\WebDrivers" ; the webdrivers are here for me
svc.HideCommandPromptWindow := True


wd.New_FirefoxDriver(svc,Options)
wd.Manage.Window.Maximize
wd.URL := "https://demoqa.com/alerts"

loop {
	ready := wd.ExecuteScript("return document.readyState")
	if (ready := "complete")
		break
	else
		sleep, 1000
}
Actions.Create(wd) 

wd.FindElementById("promtButton").click

sleep, 2000
wd.SwitchTo.Alert.SendKeys("Thoughtfu1Tux") 
sleep 2000
wd.SwitchTo.Alert.Accept
sleep 4000
msgbox, ,I will dismiss myself     , AHK filled in the prompt`nand submitted it.`nFirefox shows keys sent.`nChrome does not`!, 2


sleep 3000
wd.Quit()
; This page was helpful: https://www.toolsqa.com/selenium-webdriver/alerts-in-selenium/
Regards,
burque505

EDIT: Poor quality animation of SeleniumBasic handling popups/prompts.
handle_popups_small.gif
handle_popups_small.gif (355.71 KiB) Viewed 954 times
User avatar
Thoughtfu1Tux
Posts: 125
Joined: 31 May 2018, 23:26

Re: Selenium Chrome - Translating Python Argument into AHK

Post by Thoughtfu1Tux » 08 Apr 2021, 11:18

burque505 wrote:
23 Mar 2021, 15:44
Very very cool! Looking forward to playing around with this, thanks for the share!
Post Reply

Return to “Ask for Help (v1)”