本文整理汇总了Python中selenium.webdriver.firefox.firefox_profile.FirefoxProfile.add_extension方法的典型用法代码示例。如果您正苦于以下问题:Python FirefoxProfile.add_extension方法的具体用法?Python FirefoxProfile.add_extension怎么用?Python FirefoxProfile.add_extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.firefox.firefox_profile.FirefoxProfile
的用法示例。
在下文中一共展示了FirefoxProfile.add_extension方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getDriver
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def getDriver(httpProxy = '', type='Firefox'):
if type == 'Firefox':
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': httpProxy,
'ftpProxy': httpProxy,
'sslProxy': httpProxy,
'noProxy': '' # set this value as desired
})
firefox_profile = FirefoxProfile()
#firefox_profile.add_extension("firefox_extensions/adblock_plus-2.5.1-sm+tb+an+fx.xpi")
firefox_profile.add_extension("firefox_extensions/webdriver_element_locator-1.rev312-fx.xpi")
firefox_profile.set_preference("browser.download.folderList",2)
firefox_profile.set_preference("webdriver.load.strategy", "unstable")
#driver = webdriver.Firefox(firefox_profile = firefox_profile, proxy=proxy, firefox_binary=FirefoxBinary('/usr/bin/firefox'))
#driver = webdriver.Firefox(firefox_profile = firefox_profile, proxy=proxy, firefox_binary=FirefoxBinary("/cygdrive/c/Program\ Files\ (x86)/Mozilla\ Firefox/firefox.exe"))
driver = webdriver.Firefox(firefox_profile = firefox_profile, proxy=proxy)
elif type == 'PhantomJS': # PhantomJS
service_args = [
'--proxy='+httpProxy,
'--proxy-type=http',
]
webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.User-Agent'] = 'Mozilla/5.0 (X11; Windows x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36'
driver = webdriver.PhantomJS(executable_path='windows/phantomjs.exe', service_args=service_args)
else: # Chrome
chrome_options = webdriver.ChromeOptions()
#chrome_options.add_extension('firefox_extensions/adblockplus_1_7_4.crx')
chrome_options.add_argument('--proxy-server=%s' % httpProxy)
driver = webdriver.Chrome(executable_path='windows/chromedriver.exe', chrome_options=chrome_options)
return driver
示例2: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, profile=None, extensions=None, user_agent=None, profile_preferences=None):
self.old_popen = subprocess.Popen
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', False)
firefox_profile.set_preference('network.dns.disableIPv6', False)
if user_agent is not None:
firefox_profile.set_preference('general.useragent.override', user_agent)
if profile_preferences:
for key, value in profile_preferences.iteritems():
firefox_profile.set_preference(key, value)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
self._patch_subprocess()
self.driver = Firefox(firefox_profile)
self._unpatch_subprocess()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__()
示例3: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, profile=None, extensions=None, user_agent=None,
profile_preferences=None, fullscreen=False, wait_time=2):
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', False)
firefox_profile.set_preference('network.dns.disableIPv6', False)
if user_agent is not None:
firefox_profile.set_preference(
'general.useragent.override', user_agent)
if profile_preferences:
for key, value in profile_preferences.items():
firefox_profile.set_preference(key, value)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
self.driver = Firefox(firefox_profile)
if fullscreen:
ActionChains(self.driver).send_keys(Keys.F11).perform()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__(wait_time)
示例4: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, profile=None, extensions=None, user_agent=None,
profile_preferences=None, fullscreen=False, wait_time=2,
timeout=90, capabilities=None, headless=False, **kwargs):
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', False)
firefox_profile.set_preference('network.dns.disableIPv6', False)
firefox_capabilities = DesiredCapabilities().FIREFOX
firefox_capabilities["marionette"] = True
if 'accepted_languages' in kwargs:
firefox_profile.set_preference('intl.accept_languages', kwargs['accepted_languages'])
del kwargs['accepted_languages']
if capabilities:
for key, value in capabilities.items():
firefox_capabilities[key] = value
if user_agent is not None:
firefox_profile.set_preference(
'general.useragent.override', user_agent)
if profile_preferences:
for key, value in profile_preferences.items():
firefox_profile.set_preference(key, value)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
if headless:
os.environ.update({"MOZ_HEADLESS": '1'})
binary = FirefoxBinary()
binary.add_command_line_options('-headless')
kwargs['firefox_binary'] = binary
self.driver = Firefox(firefox_profile,
capabilities=firefox_capabilities,
timeout=timeout, **kwargs)
if fullscreen:
ActionChains(self.driver).send_keys(Keys.F11).perform()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__(wait_time)
示例5: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, profile=None, extensions=None):
self.old_popen = subprocess.Popen
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', 'false')
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
self._patch_subprocess()
self.driver = Firefox(firefox_profile)
self._unpatch_subprocess()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__()
示例6: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, default_wait_time=20, profile=None, extensions=None):
self.old_popen = subprocess.Popen
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', False)
firefox_profile.set_preference('network.dns.disableIPv6', False)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
self._patch_subprocess()
self.driver = Firefox(firefox_profile)
self._unpatch_subprocess()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__(wait_time=default_wait_time)
示例7: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, server, port=4443, profile=None, extensions=None):
self.old_popen = subprocess.Popen
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', False)
firefox_profile.set_preference('network.dns.disableIPv6', False)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
self._patch_subprocess()
dest = 'http://%s:%s/wd/hub'%(server,port)
self.driver = Remote(dest, {}, firefox_profile)
self._unpatch_subprocess()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__()
示例8: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(
self, profile=None, extensions=None, user_agent=None, profile_preferences=None, wait_time=2, firefox_path=None
):
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference("extensions.logging.enabled", False)
firefox_profile.set_preference("network.dns.disableIPv6", False)
if user_agent is not None:
firefox_profile.set_preference("general.useragent.override", user_agent)
if profile_preferences:
for key, value in profile_preferences.items():
firefox_profile.set_preference(key, value)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
if firefox_path:
firefox_binary = FirefoxBinary(firefox_path=firefox_path)
self.driver = Firefox(firefox_profile=firefox_profile, firefox_binary=firefox_binary)
else:
self.driver = Firefox(firefox_profile)
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__(wait_time)
示例9: _init_webdriver
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def _init_webdriver():
# get the Firefox profile object
fp = FirefoxProfile()
# Disable CSS
fp.set_preference('permissions.default.stylesheet', 2)
# Disable images
fp.set_preference('permissions.default.image', 2)
# Disable Flash
fp.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
'false')
# Block Pop ups
fp.set_preference('browser.popups.showPopupBlocker', 'true')
# Install ad block plus
fp.add_extension("adblockplusfirefox.xpi")
# Set the modified profile while creating the browser object
return webdriver.Firefox(fp)
示例10: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, profile=None, extensions=None, user_agent=None, profile_preferences=None, wait_time=2):
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', False)
firefox_profile.set_preference('network.dns.disableIPv6', False)
if user_agent is not None:
firefox_profile.set_preference('general.useragent.override', user_agent)
if profile_preferences:
for key, value in profile_preferences.iteritems():
firefox_profile.set_preference(key, value)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
firefox_profile.profile_dir=firefox_profile.profile_dir.encode('ascii','ignore')
self.driver = Firefox(firefox_profile)
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__(wait_time)
示例11: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(self, profile=None, extensions=None, user_agent=None,
profile_preferences=None, fullscreen=False, wait_time=2):
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference('extensions.logging.enabled', False)
firefox_profile.set_preference('network.dns.disableIPv6', False)
firefox_profile.set_preference("browser.download.folderList", 2)
firefox_profile.set_preference("browser.download.manager.showWhenStarting", False)
firefox_profile.set_preference("browser.download.dir", _DOWNLOAD_PATH)
firefox_profile.set_preference("browser.helperApps.neverAsk.saveToDisk", _ALL_MIME_TYPES)
# firefox_profile.set_preference("browser.helperApps.alwaysAsk.force", False)
# firefox_profile.set_preference("browser.download.manager.showWhenStarting", False)
if user_agent is not None:
firefox_profile.set_preference(
'general.useragent.override', user_agent)
if profile_preferences:
for key, value in profile_preferences.items():
firefox_profile.set_preference(key, value)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
self.driver = Firefox(firefox_profile)
if fullscreen:
ActionChains(self.driver).send_keys(Keys.F11).perform()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__(wait_time)
示例12: run_tests
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def run_tests(firefox_path=None):
basedir = os.path.dirname(__file__)
driver = None
profile = FirefoxProfile()
if firefox_path:
if sys.platform == "darwin" and os.path.isdir(firefox_path):
firefox_path = os.path.join(firefox_path, "Contents", "MacOS", "firefox")
binary = FirefoxBinary(firefox_path)
else:
binary = None
try:
build1 = tempfile.NamedTemporaryFile(mode="wb", suffix=".xpi", delete=False)
build2 = tempfile.NamedTemporaryFile(mode="wb", suffix=".xpi", delete=False)
try:
createBuild(basedir, type="gecko", outFile=build1)
createBuild(os.path.join(basedir, "testhelper"), type="gecko", outFile=build2)
profile.add_extension(build1.name)
profile.add_extension(build2.name)
finally:
os.unlink(build1.name)
os.unlink(build2.name)
driver = WebDriver(profile, firefox_binary=binary)
driver.wait_until = lambda method: WebDriverWait(driver, default_timeout).until(lambda d: method())
driver.accept_alert = Alert(driver).accept
driver.keys = Keys
def chain(*actions):
for action in actions:
c = ActionChains(driver)
action(c)
c.perform()
driver.chain = chain
max_timestamp = {"value": 0}
def get_urls():
result = []
prefix = "[testhelper] Loading: "
new_timestamp = max_timestamp["value"]
for item in driver.get_log("browser"):
timestamp = item["timestamp"]
if timestamp <= max_timestamp["value"] or not item["message"].startswith(prefix):
continue
if timestamp > new_timestamp:
new_timestamp = timestamp
result.append(item["message"][len(prefix):])
max_timestamp["value"] = new_timestamp
return result
driver.get_urls = get_urls
def close_background_tabs():
driver.execute_script('''
var event = document.createEvent("Events");
event.initEvent("testhelper_closeBackgroundTabs", true, false);
document.dispatchEvent(event);
''')
driver.close_background_tabs = close_background_tabs
def middle_click(self):
driver.execute_script('''
var event = document.createEvent("Events");
event.initEvent("testhelper_middleclick", true, false);
arguments[0].dispatchEvent(event);
''', self)
WebElement.middle_click = middle_click
environment = {
"__builtins__": __builtins__,
"driver": driver,
}
testdir = os.path.join(basedir, "tests")
for filename in os.listdir(testdir):
if filename.startswith(".") or not filename.endswith(".py"):
continue
filepath = os.path.join(testdir, filename)
environment["__file__"] = filepath
with open(filepath, "rb") as handle:
exec handle in environment
finally:
if driver:
driver.quit()
shutil.rmtree(profile.path, ignore_errors=True)
示例13: launch_browser
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def launch_browser(self, request=None):
request = request or self.request
if isinstance(request, str):
request = {
'browser': request
}
try:
self.request.update(request)
request = self.request
except AttributeError:
self.request = request
if 'browser' in request:
capabilities_map = {
"Firefox": DesiredCapabilities.FIREFOX,
"IExplorer": DesiredCapabilities.INTERNETEXPLORER,
"Chrome": DesiredCapabilities.CHROME,
"PhantomJS": DesiredCapabilities.PHANTOMJS,
"Safari": DesiredCapabilities.SAFARI,
}
caps = capabilities_map[request['browser']]
############################################
### Firefox
############################################
if request['browser'] == 'Firefox':
firefox_profile = FirefoxProfile()
if 'firefox' in request:
if 'preferences' in request['firefox']:
for preference in request['firefox']['preferences']:
firefox_profile.set_preference(*preference)
if 'extensions' in request['firefox']:
for extension in request['firefox']['extensions']:
extension = PurePath(request['firefox']['extensions_path'], extension)
firefox_profile.add_extension(str(extension))
if 'mime' in request['firefox']:
import shutil
shutil.copy2(request['firefox']['mime'], firefox_profile.profile_dir)
if 'capabilities' in request['firefox']:
caps.update(request['firefox']['capabilities'])
selenium_proxy = self.setup_proxy()
class Mixin(Firefox, browser.BrowsingActions): pass
self.browser = Mixin(firefox_profile, proxy=selenium_proxy, capabilities=caps)
############################################
### Internet Explorer
############################################
elif request['browser'] == 'IExplorer':
# Not a good idea => caps['nativeEvents'] = False
iedriver_server = os.path.join(request['iexplorer']['server_path'],
request['iexplorer']['server_file'])
class Mixin(Ie, browser.BrowsingActions): pass
self.browser = Mixin(iedriver_server, capabilities=caps)
############################################
### GhostDriver, PhantomJS
############################################
elif request['browser'] == 'PhantomJS':
service_args = ["--ignore-ssl-errors=yes"]
caps['phantomjs.page.settings.userAgent'] = (
'Mozilla/5.0 (Windows NT'
' 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0'
)
class Mixin(PhantomJS, browser.BrowsingActions): pass
self.browser = Mixin(service_args=service_args,
desired_capabilities=caps)
# If you don't do this, you'll get the pain:
# https://github.com/angular/protractor/issues/585
self.browser.set_window_size(1024, 768)
############################################
### Chrome
############################################
elif request['browser'] == 'Chrome':
chromedriver_server = os.path.join(request['chrome']['server_path'],
request['chrome']['server_file'])
os.environ["webdriver.chrome.driver"] = chromedriver_server
class Mixin(Chrome, browser.BrowsingActions): pass
self.browser = Mixin(chromedriver_server)
############################################
### Safari
############################################
elif request['browser'] == 'Safari':
selenium_server = os.path.join(request['safari']['server_path'],
request['safari']['server_file'])
class Mixin(Safari, browser.BrowsingActions): pass
self.browser = Mixin(selenium_server)
return self.browser
print("Please specify which browser to launch.")
assert 'browser' in request
示例14: __init__
# 需要导入模块: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile.FirefoxProfile import add_extension [as 别名]
def __init__(
self,
profile=None,
extensions=None,
user_agent=None,
profile_preferences=None,
fullscreen=False,
wait_time=2,
timeout=90,
capabilities=None,
headless=False,
incognito=False,
**kwargs
):
firefox_profile = FirefoxProfile(profile)
firefox_profile.set_preference("extensions.logging.enabled", False)
firefox_profile.set_preference("network.dns.disableIPv6", False)
firefox_capabilities = DesiredCapabilities().FIREFOX
firefox_capabilities["marionette"] = True
firefox_options = Options()
if capabilities:
for key, value in capabilities.items():
firefox_capabilities[key] = value
if user_agent is not None:
firefox_profile.set_preference("general.useragent.override", user_agent)
if profile_preferences:
for key, value in profile_preferences.items():
firefox_profile.set_preference(key, value)
if extensions:
for extension in extensions:
firefox_profile.add_extension(extension)
if headless:
os.environ.update({"MOZ_HEADLESS": "1"})
binary = FirefoxBinary()
binary.add_command_line_options("-headless")
kwargs["firefox_binary"] = binary
if incognito:
firefox_options.add_argument("-private")
self.driver = Firefox(
firefox_profile,
capabilities=firefox_capabilities,
options=firefox_options,
timeout=timeout,
**kwargs
)
if fullscreen:
ActionChains(self.driver).send_keys(Keys.F11).perform()
self.element_class = WebDriverElement
self._cookie_manager = CookieManager(self.driver)
super(WebDriver, self).__init__(wait_time)