Jump to content

Firefox + webdriver, possible to use credential autofill?


 Share

Go to solution Solved by Danp2,

Recommended Posts

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 :

#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

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)

 

Link to comment
Share on other sites

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

image.png.3a9b2ed0ee5d02ebd0c1af37e68e4ee5.png

the about:preferences#privacy config is

image.png.2f9183ce26e31fdc479b354cdb7647da.png

 

 

If i manually open FF, about:profiles displays the same result but about:preferences#privacy is 

image.png.2a179cad8eb28dd5d4184a53eeed0b46.png

 

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...