YGYL0 Posted November 16, 2024 Posted November 16, 2024 #include "wd_helper.au3" #include "wd_capabilities.au3" $bHeadless = False $sCapabilities = SetupChrome($bHeadless) If @error Then MsgBox(0, @error, @extended) Local $iWebDriver_PID = _WD_Startup() $sSession = _WD_CreateSession($sCapabilities) _WD_Navigate($sSession, 'https://www.baidu.com') _WD_LoadWait($sSession) MsgBox(0,"","OK") Func SetupChrome($bHeadless) _WD_Option('Driver', 'chromedriver.exe') Local $iPort = _WD_GetFreePort(5555, 5600) ;~ If @error Then Return SetError(@error, @extended, 0) _WD_Option('Port', $iPort) _WD_Option('DriverParams', '--port=' & $iPort & ' --verbose --log-path="' & @ScriptDir & '\chrome.log"') ;~ Local $sCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"]}}}}' _WD_CapabilitiesStartup() _WD_CapabilitiesAdd('alwaysMatch', 'chrome') _WD_CapabilitiesAdd('w3c', True) _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation') If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless') _WD_CapabilitiesDump(@ScriptLineNumber) ; dump current Capabilities setting to console - only for testing in this demo Local $sCapabilities = _WD_CapabilitiesGet() Return $sCapabilities EndFunc ;==>SetupChrome Google Chrome 131.0.6778.70 chromedriver 131.0.6778.69 au3WebDriver-1.4.0 Google Chrome for Testing 131.0.6778.69 ,install dir is d:\gct131\chrome.exe The format of "binary=". And Testing port?
Danp2 Posted November 16, 2024 Posted November 16, 2024 There's a FAQ in the wiki for specifying the location of the browser executable -- https://www.autoitscript.com/wiki/WebDriver#FAQ Latest Webdriver UDF Release Webdriver Wiki FAQs
YGYL0 Posted November 16, 2024 Author Posted November 16, 2024 1 hour ago, Danp2 said: There's a FAQ in the wiki for specifying the location of the browser executable -- https://www.autoitscript.com/wiki/WebDriver#FAQ $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "binary":"C:\\Path\\To\\Alternate\\Browser\\chrome.exe" }}}}' This format is wrong. \\ To be written as//
Danp2 Posted November 17, 2024 Posted November 17, 2024 23 hours ago, YGYL0 said: This format is wrong. \\ To be written as// Are you sure? What error did you receive? Also, take a look at SetupGecko in wd_demo for an example of using _WD_GetBrowserPath and _WD_CapabilitiesAdd to set the executable path. Latest Webdriver UDF Release Webdriver Wiki FAQs
YGYL0 Posted November 17, 2024 Author Posted November 17, 2024 51 minutes ago, Danp2 said: Are you sure? What error did you receive? Also, take a look at SetupGecko in wd_demo for an example of using _WD_GetBrowserPath and _WD_CapabilitiesAdd to set the executable path. sure,It won't work if you copy the original, After changing \\to//, it can run normally. $chromeLOC="C:\111\222\chrome.exe" ....... _WD_CapabilitiesAdd('w3c', True) _WD_CapabilitiesAdd('binary',$chromeLOC) Of course, the best way is change the code to this.
Danp2 Posted November 17, 2024 Posted November 17, 2024 Must be something different on your end because it works just fine for me with the double backslash. 🤷♂️ Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now