gsalin Posted August 17, 2023 Share Posted August 17, 2023 Hi, thank you for this forum! I created a script with autoit and webdriver in order to open firefox with the current user profile acces a URL containing a form to log in (with credentials stored by the browser, or not) If credentials are stored by the browser, then click on the submit button else, I ask the password to the user, fill the corresponding field and click on the submit button I have a problem in the case where the credentials are stored. I managed to use the current user firefox profile, which is configured to store credentials and to autofill logins and passwords (about:preferences#privacy > Ask to save logins and passwords for websites and Autofill logins and passwords are checked). If i go to the url manually, login and password are auto-filled, but with my script they didn't! Moreover, Ask to save logins and passwords for websites and Autofill logins and passwords are no longer checked!! I used the following config for firefox : Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch":{"moz:firefoxOptions":{"binary":"C:\\Program Files\\Mozilla Firefox\\firefox.exe", "args": ["-profile", "' & GetDefaultFFProfile() & '"],"log": {"level": "trace"}}}}}' and also tested Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch":{"moz:firefoxOptions":{"binary":"C:\\Program Files\\Mozilla Firefox\\firefox.exe", "args": ["-profile", "' & GetDefaultFFProfile() & '"],"log": {"level": "trace"},"prefs": {"profile.password_manager_enabled": "True"}}}}}' here is part of my script which allow to reproduce : expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <wd_core.au3> #include <wd_helper.au3> #include <ButtonConstants.au3> #include <ColorConstants.au3> #include <Date.au3> #include <Debug.au3> #include <GuiComboBoxEx.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; non standard UDF's #include "wd_helper.au3" #include "wd_capabilities.au3" Global $g_sDriver = 'geckodriver.exe' Global $g_sUrl = 'https://www.autoitscript.fr/forum/ucp.php?mode=login&redirect=index.php' Main() Func Main() ConsoleWrite("Entering script "& @CRLF) ; Local $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}' Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch":{"moz:firefoxOptions":{"binary":"C:\\Program Files\\Mozilla Firefox\\firefox.exe", "args": ["-profile", "' & GetDefaultFFProfile() & '"],"log": {"level": "trace"},"prefs": {"profile.password_manager_enabled": 1,"dom.forms.autocomplete.formautofill":1}}}}}' _WD_Option('Driver', $g_sDriver) ;~ _WD_Option('DriverParams', '--log trace') ;~ _WD_Option('DriverParams', '--log trace --connect-existing --marionette-port 2828') ;~ _WD_Option('DriverParams', '--connect-existing') _WD_Option('Port', 4444) _WD_Startup() If @error <> $_WD_ERROR_Success Then Exit -1 Local $sSession = _WD_CreateSession($sDesiredCapabilities) If @error <> $_WD_ERROR_Success Then Exit _WD_Navigate($sSession, $g_sUrl) sleep(3000) Exit EndFunc ;==>Main Func GetDefaultFFProfile() Local $sDefault, $sProfilePath = '' Local $sProfilesPath = StringReplace(@AppDataDir, '\', '/') & "/Mozilla/Firefox/" ConsoleWrite("sProfilesPath = "&$sProfilesPath& ", "&@UserProfileDir & @CRLF) Local $sFilename = $sProfilesPath & "profiles.ini" Local $aSections = IniReadSectionNames ($sFilename) If Not @error Then For $i = 1 To $aSections[0] $sDefault = IniRead($sFilename, $aSections[$i], 'Default', '0') If $sDefault = '1' Then $sProfilePath = $sProfilesPath & IniRead($sFilename, $aSections[$i], "Path", "") ExitLoop EndIf Next EndIf ConsoleWrite("sProfilePath = "&$sProfilePath & @CRLF) Return $sProfilePath EndFunc I checked GetDefaultFFProfile() returns the right profile in the log.... Any idea to allow firefox autofill with autoit/webdriver? I'm using firefox 116.0.3 (64 bits), $__WDVERSION = "1.1.1" Thank you for your help! Link to comment Share on other sites More sharing options...
Danp2 Posted August 17, 2023 Share Posted August 17, 2023 5 hours ago, gsalin said: I checked GetDefaultFFProfile() returns the right profile in the log.... Are you sure? When I checked on my system, it returns the wrong value. You can go to about:profiles in FF and review the available profiles, see which one is considered default, etc. From what I can see, it seems like there may have been a change in the way a default profile is defined. Do you get the same value when using the following? $sDefault = IniRead($sFilename, "Install308046B0AF4A39CB", 'Default', '0') ConsoleWrite("Default = " & $sDefault & @CRLF) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
gsalin Posted August 18, 2023 Author Share Posted August 18, 2023 Hi and thank you for your work and interest with your code, I get in log : Default = Profiles/autoit.default-release with my code, i get in scite log sProfilesPath = C:/Users/gsalin/AppData/Roaming/Mozilla/Firefox/Profiles/autoit.default-release and in geckodriver log 1692340429394 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-profile" "C:/Users/gsalin/AppData/Roaming/Mozilla/Firefox/Profiles/autoit.default-release" "-no-remote" After calling my script, i did about:profiles in FF, and it seems the right profile is called : the about:preferences#privacy config is If i manually open FF, about:profiles displays the same result but about:preferences#privacy is Link to comment Share on other sites More sharing options...
Solution Danp2 Posted August 18, 2023 Solution Share Posted August 18, 2023 I haven't tried this myself, but you should be able to enable those options by passing the correct values for these preferences in your Capabilities string -- signon.rememberSignons signon.autofillForms HTH, Dan Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
gsalin Posted August 18, 2023 Author Share Posted August 18, 2023 pfiouuu!!! thank you Danp2.... In fact, it seems geckodriver is setting default values to some configs (https://github.com/mozilla/geckodriver/pull/222/files#diff-ccfd81fdb66b11234ea8ca7021e0da03dacaea8e5cced67f6e8fd390a7d72dc1R103) I didn't have the keys for the configs about:preferences#privacy > Ask to save logins and passwords for websites and Autofill logins and passwords.....where do you find the corresponding config keys? moreover, i set the value to "True"...which didn't raised an error, but had no effect on the configuration..... lastly replaced "True" with true....and it worked!!!!!! Thank you Danp2 for your work and help!! Now my script works as expected!!! Danp2 1 Link to comment Share on other sites More sharing options...
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