zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
U
\±d#ã@s^ddlZddlZddlmZddlmZddlmZddlmZddl    m
Z
Gdd„dƒZ dS)    éN)Úsystem)ÚSTDOUT)ÚPopen)ÚWebDriverException)Úutilsc@sveZdZdZddd„Zdd„Zddd    „Zd
d „Zd d „Zddd„Z    dd„Z
dd„Z dd„Z dd„Z dd„Zdd„ZdS)Ú FirefoxBinaryzx_ignore_nofocus.soNcCsz||_|pttjdƒ|_d|_tƒ ¡|_|js:|     ¡|_|j 
¡sLt dƒ‚tj   ¡|_d|jd<d|jd<d|jd<dS)a¾Creates a new instance of Firefox binary.
 
        :Args:
         - firefox_path - Path to the Firefox executable. By default, it will be detected from the standard locations.
         - log_file - A file object to redirect the firefox process output to. It can be sys.stdout.
                      Please note that with parallel run the output won't be synchronous.
                      By default, it will be redirected to /dev/null.
        ÚwbNzûFailed to find firefox binary. You can set it by specifying the path to 'firefox_binary':
 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
 
binary = FirefoxBinary('/path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)Ú1ZMOZ_CRASHREPORTER_DISABLEZ MOZ_NO_REMOTEZ NO_EM_RESTART)Ú
_start_cmdÚopenÚosÚdevnullÚ    _log_fileÚ command_linerÚlowerÚplatformÚ_get_firefox_start_cmdÚstriprÚenvironÚcopyÚ _firefox_env)ÚselfZ firefox_pathZlog_file©rú`d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\selenium/webdriver/firefox/firefox_binary.pyÚ__init__ s     
 
ÿ
 
 
zFirefoxBinary.__init__cGs
||_dS)N)r)rÚargsrrrÚadd_command_line_optionsAsz&FirefoxBinary.add_command_line_optionsécCs$||_| |jj¡|j|ddS)zlLaunches the browser for the given profile name.
 
        It is assumed the profile already exists.
        )ÚtimeoutN)ÚprofileÚ_start_from_profile_pathÚpathÚ_wait_until_connectable)rrrrrrÚlaunch_browserDszFirefoxBinary.launch_browsercCs|jr|j ¡|j ¡dS)zMKill the browser.
 
        This is useful when the browser is stuck.
        N)ÚprocessÚkillÚwait)rrrrr%Ns
zFirefoxBinary.killcCs\||jd<|jdkr| ¡|jdg}|jrB|jD]}| |¡q2t||jt|jd|_    dS)NZXRE_PROFILE_PATHÚlinuxz -foreground)ÚstdoutÚstderrÚenv)
rrÚ_modify_link_library_pathr
rÚappendrrrr$)rr!ÚcommandÚclirrrr Ws
 
 
 
 z&FirefoxBinary._start_from_profile_pathcCs`d}t |jj¡s\|j ¡r$tdƒ‚||krH| ¡td|jj›dƒ‚|d7}t     
d¡qdS)z9Blocks until the extension is connectable in the firefox.rzThe browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.zzCan't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: zT If you specified a log_file in the FirefoxBinary constructor, check it for details.éT) rZis_connectablerÚportr$Úpollrr%r!ÚtimeÚsleep)rrÚcountrrrr"bs
ÿÿ z%FirefoxBinary._wait_until_connectablec
Csz4ddlm}ddlm}ddlm}ddlm}Wn,tk
r`ddlm}m}m}m}YnXddl}d}d}|D]n}z|||ƒ}    ||    dƒ}WqêWqvtk
râz |||ƒ}    ||    dƒ}WYqêWntk
rÜYnXYqvXqvdS|sòdS|     |¡dS)    Nr)ÚHKEY_CURRENT_USER)ÚHKEY_LOCAL_MACHINE)ÚOpenKey)Ú
QueryValue)r7r8r6r5)z/SOFTWARE\Classes\FirefoxHTML\shell\open\commandz<SOFTWARE\Classes\Applications\firefox.exe\shell\open\commandÚ)
Ú_winregr5r6r7r8Ú ImportErrorÚwinregÚshlexÚOSErrorÚsplit)
rr5r6r7r8r=Úkeysr-r!ÚkeyrrrÚ_find_exe_in_registryys4   
 
 
 
 
 z#FirefoxBinary._find_exe_in_registrycCs¤d}|jdkrBd}| |¡}|s$d}tj |¡s tj d¡|}n^|jdkr^| ¡pZ| ¡}nB|jdkr|tjdkr|| ¡}n$d    D]}| |¡}|r€q q€t    d
ƒ‚|S) z$Return the command to start firefox.r9ÚdarwinÚfirefoxz4/Applications/Firefox.app/Contents/MacOS/firefox-binú~ZwindowsÚjavaÚnt)rDZ    iceweaselziCould not find firefox in your system PATH. Please specify the firefox binary location or install firefox)
rÚwhichr r!ÚexistsÚ
expanduserrBÚ_default_windows_locationÚnameÚ RuntimeError)rZ    start_cmdZffnamerrrrœs(
 
 
 
 
ÿz$FirefoxBinary._get_firefox_start_cmdcCsJt dd¡t dd¡g}|D](}tj |d¡}t |tj¡r|SqdS)NZ PROGRAMFILESzC:\Program FileszPROGRAMFILES(X86)zC:\Program Files (x86)zMozilla Firefox\firefox.exer9)r Úgetenvr!ÚjoinÚaccessÚX_OK)rZ program_filesr!Z binary_pathrrrrK¹s
 
þ
z'FirefoxBinary._default_windows_locationcCs@tj dd¡}| |jdd¡}||7}||jd<|j|jd<dS)NZLD_LIBRARY_PATHr9Úx86Úamd64Z
LD_PRELOAD)r rÚgetÚ_extract_and_checkrrÚNO_FOCUS_LIBRARY_NAME)rZexisting_ld_lib_pathZnew_ld_lib_pathrrrr+Äs
 
z'FirefoxBinary._modify_link_library_pathc    Csv||g}d}|D]`}tj |j|¡}tj |¡s:t |¡ddl}| tj tj t¡||j    ¡|¡||d7}q|S)Nr9rú:)
r r!rOrIÚmakedirsÚshutilrÚdirnameÚ__file__rV)    rrrRrSÚpathsZ
built_pathr!Z library_pathrYrrrrUÎs 
"z FirefoxBinary._extract_and_checkcCsLtjd tj¡D]4}tj ||¡}t |tj¡rtj |¡s|SqdS)zMReturns the fully qualified path by searching Path of the given
        name.ÚPATHN)    r rr?Úpathsepr!rOrPrQÚisdir)rÚfnameÚpeZ    checknamerrrrHÜs
 
zFirefoxBinary.which)NN)r)r)Ú__name__Ú
__module__Ú __qualname__rVrrr#r%r r"rBrrKr+rUrHrrrrrs
!
 
    
# 
r) r r2rrÚ
subprocessrrZselenium.common.exceptionsrZselenium.webdriver.commonrrrrrrÚ<module>s