1 existing_ld_lib_path = os.environ.get('LD_LIBRARY_PATH', '')
该语句是将名为LD_LIBRARY_PATH的环境变量赋予existing_ld_lib_path
2 shutil.copy(os.path.join(os.path.dirname(__file__), path,self.NO_FOCUS_LIBRARY_NAME), library_path)
将 library_path中的文件复制到os.path.dirname(__file__), path,self.NO_FOCUS_LIBRARY_NAME)中的文件去。
3 key = OpenKey(HKEY_LOCAL_MACHINE, path)
打开注册表中特定KEY 该方法用于注册表寻找程序
4 self.process = Popen( command, stdout=self._log_file, stderr=STDOUT, env=self._firefox_env)
下面是Selemium启动firefox的源码,有时间补上注释
import os
import platform
from subprocess import Popen, STDOUT
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common import utils
import time
class FirefoxBinary(object):
NO_FOCUS_LIBRARY_NAME = "x_ignore_nofocus.so"
def __init__(self, firefox_path=None, log_file=None):
"""
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.
"""
self._start_cmd = firefox_path
# We used to default to subprocess.PIPE instead of /dev/null, but after
# a while the pipe would fill up and Firefox would freeze.
self._log_file = log_file or open(os.devnull, "wb")
self.command_line = None
if self._start_cmd is None:
self._start_cmd =