If anyone's willing to use the
SeleniumBasic 3.141.0.0 - not many so far apparently,
then this code may be of some use.
@malcev, you'll no doubt notice right away that the syntax is different than that of the older version, but is more in line with what can be found on the web.
Code: Select all
[;https://www.autohotkey.com/boards/viewtopic.php?f=7&t=87159
SetBatchLines, -1
; Run, C:\Chromium\chrome-win\chrome.exe ; "--remote-debugging-port=9333"
; sleep, 2000
wd := ComObjCreate("SeleniumBasic.IWebDriver")
svc := ComObjCreate("SeleniumBasic.ChromeDriverService")
options := ComObjCreate("SeleniumBasic.ChromeOptions")
svc.CreateDefaultService.driverPath := "C:\Chromium" ; the webdrivers are here for me
svc.HideCommandPromptWindow := True
options.BinaryLocation := "C:\Chromium\chrome-win\chrome.exe" ;
options.AddArgument("--start-maximized")
wd.New_ChromeDriver(svc,Options)
wd.URL := "https://www.autohotkey.com"
loop {
ready := wd.ExecuteScript("return document.readyState")
if (ready := "complete")
break
else
sleep, 1000
}
Actions.Create(wd) ; superfluous
wd.ExecuteScript("alert('I want to click this programmatically');")
sleep, 3000
wd.SwitchTo.Alert.Accept
sleep 5000
wd.Quit()
; This page was helpful: https://www.toolsqa.com/selenium-webdriver/alerts-in-selenium//code]
EDIT: Some experimenting is proving useful. The text from the alert can be grabbed.
EDIT: Here is some code showing how to send keys to popups. It is for Firefox (there seems to be bug in the Chromedriver.exe and msedgedriver.exe recently that affects SendKeys).
N.B.: The code still works (with the obvious required changes for Chrome and Edge), but you won't see the text displayed in the popup. However, the page we're testing with will show you that what you typed was actually entered).
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
options.AddArgument("--start-maximized")
wd.New_FirefoxDriver(svc,Options)
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("Winter") ; text appears for FF
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: Code for Edge.