本文整理汇总了Python中selenium.webdriver.firefox.firefox_profile.FirefoxProfile方法的典型用法代码示例。如果您正苦于以下问题:Python firefox_profile.FirefoxProfile方法的具体用法?Python firefox_profile.FirefoxProfile怎么用?Python firefox_profile.FirefoxProfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.firefox.firefox_profile
的用法示例。
在下文中一共展示了firefox_profile.FirefoxProfile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _webdriver
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def _webdriver(self):
className = self._driverClassName()
self._remoteUsername = self._remoteUsername()
remoteURL = self._remoteURL()
capabilities = self._capabilities()
if remoteURL:
self.log("RemoteURL")
# Remote driver requires a executor (typically a Remote URL)
browserProfile = FirefoxProfile()
return webdriver.Remote(command_executor = remoteURL, keep_alive = True, \
browser_profile = browserProfile, desired_capabilities = capabilities)
clazz = self._driverClass(className)
try:
self.log("" + className + "(capabilities)")
return clazz(desired_capabilities = capabilities)
except Exception:
self.log("Setting up " + className)
if className == 'PhantomJS':
# PhantomJS cannot handle capabilities
self.log("Creating " + className)
return clazz()
else:
# Firefox and Ie drivers have different name for desired capabilities parameter
#return clazz(capabilities = capabilities)
return clazz()
示例2: profile
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def profile(self):
"""
Returns a FirefoxProfile object if one has been set before else None
"""
return self._profile
示例3: __init__
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
capabilities=None, proxy=None):
self.binary = firefox_binary
self.profile = firefox_profile
if self.profile is None:
self.profile = FirefoxProfile()
self.profile.native_events_enabled = (
self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled)
if self.binary is None:
self.binary = FirefoxBinary()
if capabilities is None:
capabilities = DesiredCapabilities.FIREFOX
if proxy is not None:
proxy.add_to_capabilities(capabilities)
RemoteWebDriver.__init__(self,
command_executor=ExtensionConnection("127.0.0.1", self.profile,
self.binary, timeout),
desired_capabilities=capabilities,
keep_alive=True)
self._is_remote = False
示例4: profile
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def profile(self, new_profile):
"""Sets location of the browser profile to use, either by string
or ``FirefoxProfile``.
"""
if not isinstance(new_profile, FirefoxProfile):
new_profile = FirefoxProfile(new_profile)
self._profile = new_profile
示例5: fetch
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def fetch(config, fileobj):
user, password = config
# use the user's regular firefox profile instead of a fresh temporary one.
# this is to avoid getting fingerprinted as a new device which generates
# annoying emails and asks for additional info. luckily this profile is
# cloned into a temporary directory, so we can change preferences without
# affecting the original copy.
profile = FirefoxProfile(_firefox_default_profile())
# disable a json viewer that's enabled by default in firefox 53+.
profile.set_preference('devtools.jsonview.enabled', False)
driver = Firefox(profile)
driver.get('https://venmo.com/account/sign-in/')
user_elem = driver.find_element_by_name('phoneEmailUsername')
user_elem.clear()
user_elem.send_keys(user.value)
password_elem = driver.find_element_by_name('password')
password_elem.clear()
password_elem.send_keys(password.value)
password_elem.send_keys(Keys.RETURN)
WebDriverWait(driver, 15).until(title_contains('Welcome'))
params = '?start_date=2009-01-01&end_date={}-01-01'.format(datetime.now().year + 1)
url = 'https://api.venmo.com/v1/transaction-history' + params
driver.get(url)
# validate json and raise ValueError on failure.
pre = driver.find_element_by_tag_name('pre').text
json.loads(pre)
driver.quit()
fileobj.write('{}\n'.format(user.value))
fileobj.write(pre)
示例6: test_accepts_firefox_profile
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def test_accepts_firefox_profile(self, browser_manager, webserver):
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
home_page = webserver.path_for('special_chars.html')
profile = FirefoxProfile()
profile.set_preference('browser.startup.homepage', home_page)
profile.set_preference('browser.startup.page', 1)
kwargs = browser_manager.kwargs.copy()
kwargs['options'] = {'profile': profile}
new_browser = Browser(**kwargs)
try:
assert new_browser.url == home_page
finally:
new_browser.quit()
示例7: __init__
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
capabilities=None, proxy=None, executable_path="wires", firefox_options=None):
capabilities = capabilities or DesiredCapabilities.FIREFOX.copy()
self.profile = firefox_profile or FirefoxProfile()
self.profile.native_events_enabled = (
self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled)
self.binary = firefox_binary or capabilities.get("binary", FirefoxBinary())
self.options = firefox_options or Options()
self.options.binary_location = self.binary if isinstance(self.binary, basestring) else self.binary._start_cmd
self.options.profile = self.profile
capabilities.update(self.options.to_capabilities())
# marionette
if capabilities.get("marionette"):
self.service = Service(executable_path, firefox_binary=self.options.binary_location)
self.service.start()
executor = FirefoxRemoteConnection(
remote_server_addr=self.service.service_url)
RemoteWebDriver.__init__(
self,
command_executor=executor,
desired_capabilities=capabilities,
keep_alive=True)
else:
# Oh well... sometimes the old way is the best way.
if proxy is not None:
proxy.add_to_capabilities(capabilities)
executor = ExtensionConnection("127.0.0.1", self.profile,
self.binary, timeout)
RemoteWebDriver.__init__(
self,
command_executor=executor,
desired_capabilities=capabilities,
keep_alive=True)
self._is_remote = False
示例8: setUpClass
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def setUpClass(cls):
super(SeleniumTests, cls).setUpClass()
cls.firefox_profile = FirefoxProfile()
server_url = config('TEST_PUSH_SERVER_URL', default=False)
if server_url:
cls.firefox_profile.set_preference('dom.push.serverURL',
server_url)
cls.selenium = WebDriver(firefox_profile=cls.firefox_profile)
示例9: StartBrowser
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def StartBrowser(browserChoice):
if browserChoice == 1:
print ('\nLaunching Chrome')
browser = webdriver.Chrome()
if browserChoice == 2:
print ('\nLaunching Firefox/Iceweasel')
browser = webdriver.Firefox()
if browserChoice == 3:
print ('\nLaunching Firefox/Iceweasel (light)')
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
firefoxLightProfile = FirefoxProfile()
firefoxLightProfile.set_preference('permissions.default.stylesheet', 2) # Disable CSS
firefoxLightProfile.set_preference('permissions.default.image', 2) # Disable images
firefoxLightProfile.set_preference('javascript.enabled', False) # Disable javascript
firefoxLightProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', False) # Disable Flash
firefoxLightProfile.set_preference('browser.chrome.toolbar_style', 0) # Display toolbar buttons with icons only, no text
browser = webdriver.Firefox(firefoxLightProfile)
if browserChoice == 4:
print ('\nLaunching PhantomJS')
browser = webdriver.PhantomJS()
if browserChoice == 5:
print ('\nLaunching PhantomJS (light)')
browser = webdriver.PhantomJS()
browser.desired_capabilities['userAgent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36'
browser.desired_capabilities['javascriptEnabled'] = False
browser.desired_capabilities['loadImages'] = False
browser.desired_capabilities['webSecurityEnabled'] = False
# Open, load and close the 'config' file
with open('config', 'r') as configFile:
config = [line.strip() for line in configFile]
configFile.close()
# Sign in
browser.get('https://linkedin.com/uas/login')
emailElement = browser.find_element_by_id('session_key-login')
emailElement.send_keys(config[0])
passElement = browser.find_element_by_id('session_password-login')
passElement.send_keys(config[1])
passElement.submit()
print ('Signing in...')
time.sleep(3)
soup = BeautifulSoup(browser.page_source)
if soup.find('div', {'class':'alert error'}):
print ('Error! Please verify your username and password.')
browser.quit()
elif browser.title == '403: Forbidden':
print ('LinkedIn is momentarily unavailable. Please wait a moment, then try again.')
browser.quit()
else:
print ('Success!\n')
LInBot(browser)
示例10: __init__
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
capabilities=None, proxy=None, executable_path="wires"):
self.binary = firefox_binary
self.profile = firefox_profile
if self.profile is None:
self.profile = FirefoxProfile()
self.profile.native_events_enabled = (
self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled)
if capabilities is None:
capabilities = DesiredCapabilities.FIREFOX
# marionette
if capabilities.get("marionette"):
self.binary = capabilities.get("binary")
self.service = Service(executable_path, firefox_binary=self.binary)
self.service.start()
executor = FirefoxRemoteConnection(
remote_server_addr=self.service.service_url)
RemoteWebDriver.__init__(
self,
command_executor=executor,
desired_capabilities=capabilities,
keep_alive=True)
else:
# Oh well... sometimes the old way is the best way.
if self.binary is None:
self.binary = FirefoxBinary()
if proxy is not None:
proxy.add_to_capabilities(capabilities)
executor = ExtensionConnection("127.0.0.1", self.profile,
self.binary, timeout)
RemoteWebDriver.__init__(self,
command_executor=executor,
desired_capabilities=capabilities,
keep_alive=True)
self._is_remote = False
示例11: launch_browser
# 需要导入模块: from selenium.webdriver.firefox import firefox_profile [as 别名]
# 或者: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile [as 别名]
def launch_browser():
if env.RUNNING_BROWSER.upper() == "FIREFOX":
# the end of the browser process , the end of the browser driven process
os.popen("TASKKILL /F /IM firefoxdriver.exe")
fp = FirefoxProfile()
fp.native_events_enabled = False
binary_path = PublicImp.common.get_value_from_conf("FIREFOX_BINARY_PATH")
if binary_path == "":
env.driver = selenium.webdriver.Firefox(firefox_profile=fp)
else:
fb = FirefoxBinary(firefox_path=binary_path)
env.driver = selenium.webdriver.Firefox(firefox_profile=fp, firefox_binary=fb)
elif env.RUNNING_BROWSER.upper() == "CHROME":
os.popen("TASKKILL /F /IM chromedriver.exe")
binary_path = PublicImp.common.get_value_from_conf("CHROME_BINARY_PATH")
chromedriver = PublicImp.common.get_value_from_conf("DRIVER_CHROME")
if binary_path == "":
os.environ["webdriver.chrome.driver"] = chromedriver
env.driver = selenium.webdriver.Chrome(executable_path=chromedriver)
else:
opts = Options()
opts.binary_location = binary_path
os.environ["webdriver.chrome.driver"] = chromedriver
env.driver = selenium.webdriver.Chrome(executable_path=chromedriver, chrome_options=opts)
elif env.RUNNING_BROWSER.upper() == "IE":
os.popen("TASKKILL /F /IM IEDriverServer.exe")
dc = DesiredCapabilities.INTERNETEXPLORER.copy()
dc['acceptSslCerts'] = True
dc['nativeEvents'] = True
iedriver = PublicImp.common.get_value_from_conf("DRIVER_IE")
os.environ["webdriver.ie.driver"] = iedriver
env.driver = selenium.webdriver.Ie(executable_path=iedriver, capabilities=dc)
else:
return False
env.platformName = env.RUNNING_BROWSER
env.TEST_URL = PublicImp.common.get_value_from_conf("TESTING_URL")
env.driver.get(env.TEST_URL)
env.driver.maximize_window()
time.sleep(3)
env.driver.refresh()
# env.driver.set_window_size(480, 800)
time.sleep(3)
return True