本文整理汇总了Python中selenium.webdriver.Edge方法的典型用法代码示例。如果您正苦于以下问题:Python webdriver.Edge方法的具体用法?Python webdriver.Edge怎么用?Python webdriver.Edge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver
的用法示例。
在下文中一共展示了webdriver.Edge方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: driver
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def driver(self, browser):
if browser == 'firefox':
return webdriver.Firefox()
if browser == 'chrome':
return webdriver.Chrome('chromedriver.exe')
if browser == 'opera':
# TODO: Opera implementation is quite buggy annoyingly. It won't close at the moment
# Need to investigate.
options = webdriver.ChromeOptions()
options.binary_location = "C:\\Program Files\\Opera\\launcher.exe"
return webdriver.Opera(executable_path='operadriver.exe', opera_options=options)
if browser == 'ie':
return webdriver.Ie()
if browser == 'edge':
# TODO: check for Windows < 8.1?
return webdriver.Edge()
if browser == 'phantom':
return webdriver.PhantomJS()
raise XVEx("{} is not supported on {}".format(browser, self._device.os_name()))
示例2: post_init
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def post_init(self):
"""Perform all required post-init tweaks and workarounds. Should be
called _after_ proceeding to desired url.
:return: None
"""
# Workaround 'Certificate Error' screen on Microsoft Edge
if (
self.browser == 'edge' and
('Certificate Error' in self._webdriver.title or
'Login' not in self._webdriver.title)):
self._webdriver.get(
"javascript:document.getElementById('invalidcert_continue')"
".click()"
)
# Workaround maximize_window() not working with chrome in docker
if not (self.provider == 'docker' and
self.browser == 'chrome'):
self._webdriver.maximize_window()
示例3: _setup_edge
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def _setup_edge(self, capabilities):
"""Setup Edge webdriver
:param capabilities: capabilities object
:returns: a new local Edge driver
"""
edge_driver = self.config.get('Driver', 'edge_driver_path')
self.logger.debug("Edge driver path given in properties: %s", edge_driver)
return webdriver.Edge(edge_driver, capabilities=capabilities)
示例4: test_edge_manager_with_selenium
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def test_edge_manager_with_selenium():
if os_name() == 'win':
driver_path = EdgeChromiumDriverManager(os_type=os_type()).install()
driver = webdriver.Edge(executable_path=driver_path)
driver.get("http://automation-remarks.com")
driver.quit()
else:
driver_path = EdgeChromiumDriverManager(os_type="win32").install()
assert os.path.exists(driver_path)
示例5: test_edge_manager_with_wrong_version
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def test_edge_manager_with_wrong_version():
with pytest.raises(ValueError) as ex:
driver_path = EdgeChromiumDriverManager("0.2",
os_type='win64').install()
driver = webdriver.Edge(executable_path=driver_path)
driver.quit()
assert "There is no such driver by url "\
"https://msedgedriver.azureedge.net/0.2/edgedriver_win64.zip" in \
ex.value.args[0]
# TODO: add "mac64" when https://msedgedriver.azureedge.net/LATEST_STABLE
# return edgedriver > 82
# see:
# https://msedgewebdriverstorage.z22.web.core.windows.net/?prefix=82.0.418.0/
示例6: get_webdriver
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def get_webdriver():
"""Get whatever webdriver is availiable in the system.
webdriver_manager and selenium are currently being used for this.
Supported browsers:[Firefox, Chrome, Opera, Microsoft Edge, Internet Expolorer]
Returns:
a webdriver that can be used for scraping. Returns None if we don't find a supported webdriver.
"""
try:
driver = webdriver.Firefox(
executable_path=GeckoDriverManager().install())
except Exception:
try:
driver = webdriver.Chrome(ChromeDriverManager().install())
except Exception:
try:
driver = webdriver.Ie(IEDriverManager().install())
except Exception:
try:
driver = webdriver.Opera(
executable_path=OperaDriverManager().install())
except Exception:
try:
driver = webdriver.Edge(
EdgeChromiumDriverManager().install())
except Exception:
driver = None
logging.error(
"Your browser is not supported. Must have one of the following installed to scrape: [Firefox, Chrome, Opera, Microsoft Edge, Internet Expolorer]")
return driver
示例7: create_driver
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def create_driver():
try:
web = webdriver.Firefox()
print " [*] Opening Mozila FireFox..."
return web
except:
try:
web = webdriver.Chrome()
print " [*] We got some errors running Firefox, Opening Google Chrome instead..."
return web
except:
try:
web = webdriver.Opera()
print " [*] We got some errors running Chrome, Opening Opera instead..."
return web
except:
try:
web = webdriver.Edge()
print " [*] We got some errors running Opera, Opening Edge instead..."
return web
except:
try:
web = webdriver.Ie()
print " [*] We got some errors running Edge, Opening Internet Explorer instead..."
return web
except:
print " Error: \n Can not call any WebBrowsers\n Check your Installed Browsers!"
exit()
#Stolen from stackoverflow :D
示例8: get_browser
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def get_browser(browser_name, capabilities=None, **options):
"""
Returns an instance of the given browser with the given capabilities.
Args:
browser_name (str): The name of the desired browser.
capabilities (Dict[str, str | bool], optional): The desired capabilities of the browser.
Defaults to None.
options: Arbitrary keyword arguments for the browser-specific subclass of
:class:`webdriver.Remote`.
Returns:
WebDriver: An instance of the desired browser.
"""
if browser_name == "chrome":
return webdriver.Chrome(desired_capabilities=capabilities, **options)
if browser_name == "edge":
return webdriver.Edge(capabilities=capabilities, **options)
if browser_name in ["ff", "firefox"]:
return webdriver.Firefox(capabilities=capabilities, **options)
if browser_name in ["ie", "internet_explorer"]:
return webdriver.Ie(capabilities=capabilities, **options)
if browser_name == "phantomjs":
return webdriver.PhantomJS(desired_capabilities=capabilities, **options)
if browser_name == "remote":
return webdriver.Remote(desired_capabilities=capabilities, **options)
if browser_name == "safari":
return webdriver.Safari(desired_capabilities=capabilities, **options)
raise ValueError("unsupported browser: {}".format(repr(browser_name)))
示例9: _get_selenium_browser
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Edge [as 别名]
def _get_selenium_browser(self):
"""Returns selenium webdriver instance of selected ``browser``.
Note: should not be called directly, use :meth:`get_browser` instead.
:raises: ValueError: If wrong ``browser`` specified.
"""
kwargs = {}
binary = settings.selenium.webdriver_binary
browseroptions = settings.selenium.browseroptions
if self.browser == 'chrome':
if binary:
kwargs.update({'executable_path': binary})
options = webdriver.ChromeOptions()
prefs = {'download.prompt_for_download': False}
options.add_experimental_option("prefs", prefs)
options.add_argument('disable-web-security')
options.add_argument('ignore-certificate-errors')
if browseroptions:
for opt in browseroptions.split(';'):
options.add_argument(opt)
kwargs.update({'options': options})
self._webdriver = webdriver.Chrome(**kwargs)
elif self.browser == 'firefox':
if binary:
kwargs.update({'executable_path': binary})
self._webdriver = webdriver.Firefox(**kwargs)
elif self.browser == 'ie':
if binary:
kwargs.update({'executable_path': binary})
self._webdriver = webdriver.Ie(**kwargs)
elif self.browser == 'edge':
if binary:
kwargs.update({'executable_path': binary})
capabilities = webdriver.DesiredCapabilities.EDGE.copy()
capabilities['acceptSslCerts'] = True
capabilities['javascriptEnabled'] = True
kwargs.update({'capabilities': capabilities})
self._webdriver = webdriver.Edge(**kwargs)
elif self.browser == 'phantomjs':
self._webdriver = webdriver.PhantomJS(
service_args=['--ignore-ssl-errors=true'])
if self._webdriver is None:
raise ValueError(
'"{}" webdriver is not supported. Please use one of {}'
.format(
self.browser,
('chrome', 'firefox', 'ie', 'edge', 'phantomjs')
)
)
self._set_session_cookie()
return self._webdriver