我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用selenium.webdriver.Opera()。
def __init__(self, driver, browser='chrome'): """ initialize selenium webdriver, use chrome as default webdriver """ if not driver: if browser == "firefox" or browser == "ff": driver = webdriver.Firefox() elif browser == "chrome": driver = webdriver.Chrome() elif browser == "internet explorer" or browser == "ie": driver = webdriver.Ie() elif browser == "opera": driver = webdriver.Opera() elif browser == "phantomjs": driver = webdriver.PhantomJS() try: self.driver = driver self.wait = WebDriverWait(self.driver, 20) except Exception: raise NameError("Not found %s browser,You can enter 'ie', 'ff' or 'chrome'." % browser) else: self.driver = driver self.wait = WebDriverWait(self.driver, 20)
def _make_opera(self , remote , desired_capabilities , profile_dir): return self._generic_make_browser(webdriver.Opera, webdriver.DesiredCapabilities.OPERA, remote, desired_capabilities)
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
def run_local(self,os_name,os_version,browser,browser_version): "Return the local driver" local_driver = None if browser.lower() == "ff" or browser.lower() == 'firefox': local_driver = webdriver.Firefox() elif browser.lower() == "ie": local_driver = webdriver.Ie() elif browser.lower() == "chrome": local_driver = webdriver.Chrome() elif browser.lower() == "opera": local_driver = webdriver.Opera() elif browser.lower() == "safari": local_driver = webdriver.Safari() return local_driver
def env_driver(browser): """ Return the web driver. Args: browser: string Returns: selenium WebDriver """ from selenium import webdriver the_driver = False if browser == 'chrome': the_driver = webdriver.Chrome elif browser == 'firefox': the_driver = webdriver.Firefox elif browser == 'safari': the_driver = webdriver.Safari elif browser == 'phantomjs': the_driver = webdriver.PhantomJS elif browser == 'opera': the_driver = webdriver.Opera return the_driver
def mode_local(self): """Open new brower on local mode""" browser_name = self.bot_config.config['browser'] if browser_name == "chrome": self.curr_caps = DesiredCapabilities.CHROME.copy() self.curr_driver = WebDriver.Chrome( executable_path=self.curr_driver_path, desired_capabilities=self.curr_caps ) elif browser_name == "firefox": self.curr_caps = DesiredCapabilities.FIREFOX.copy() self.curr_driver = WebDriver.Firefox( executable_path=self.curr_driver_path, capabilities=self.curr_caps ) elif browser_name == "iexplorer": self.curr_caps = DesiredCapabilities.INTERNETEXPLORER.copy() self.curr_driver = WebDriver.Ie( executable_path=self.curr_driver_path, capabilities=self.curr_caps ) elif browser_name == "edge": self.curr_caps = DesiredCapabilities.EDGE.copy() self.curr_driver = WebDriver.Edge( executable_path=self.curr_driver_path, capabilities=self.curr_caps ) elif browser_name == "phantomjs": self.curr_caps = DesiredCapabilities.PHANTOMJS.copy() self.curr_driver = WebDriver.PhantomJS( executable_path=self.curr_driver_path, desired_capabilities=self.curr_caps ) elif browser_name == "opera": self.curr_caps = DesiredCapabilities.OPERA.copy() self.curr_driver = WebDriver.Opera( executable_path=self.curr_driver_path, desired_capabilities=self.curr_caps ) else: raise CoreException( message=("config file error, SECTION=bot, KEY=browser isn't " "valid value: {}".format(browser_name)), log=self.log )
def create_webdriver(self, driver_name, alias=None, kwargs={}, **init_kwargs): """Creates an instance of a WebDriver. Like `Open Browser`, but allows passing arguments to a WebDriver's __init__. _Open Browser_ is preferred over _Create Webdriver_ when feasible. Returns the index of this browser instance which can be used later to switch back to it. Index starts from 1 and is reset back to it when `Close All Browsers` keyword is used. See `Switch Browser` for example. `driver_name` must be the exact name of a WebDriver in _selenium.webdriver_ to use. WebDriver names include: Firefox, Chrome, Ie, Opera, Safari, PhantomJS, and Remote. Use keyword arguments to specify the arguments you want to pass to the WebDriver's __init__. The values of the arguments are not processed in any way before being passed on. For Robot Framework < 2.8, which does not support keyword arguments, create a keyword dictionary and pass it in as argument `kwargs`. See the [http://selenium.googlecode.com/git/docs/api/py/api.html|Selenium API Documentation] for information about argument names and appropriate argument values. Examples: | # use proxy for Firefox | | | | | ${proxy}= | Evaluate | sys.modules['selenium.webdriver'].Proxy() | sys, selenium.webdriver | | ${proxy.http_proxy}= | Set Variable | localhost:8888 | | | Create Webdriver | Firefox | proxy=${proxy} | | | # use a proxy for PhantomJS | | | | | ${service args}= | Create List | --proxy=192.168.132.104:8888 | | | Create Webdriver | PhantomJS | service_args=${service args} | | Example for Robot Framework < 2.8: | # debug IE driver | | | | | ${kwargs}= | Create Dictionary | log_level=DEBUG | log_file=%{HOMEPATH}${/}ie.log | | Create Webdriver | Ie | kwargs=${kwargs} | | """ if not isinstance(kwargs, dict): raise RuntimeError("kwargs must be a dictionary.") for arg_name in kwargs: if arg_name in init_kwargs: raise RuntimeError("Got multiple values for argument '%s'." % arg_name) init_kwargs[arg_name] = kwargs[arg_name] driver_name = driver_name.strip() try: creation_func = getattr(webdriver, driver_name) except AttributeError: raise RuntimeError("'%s' is not a valid WebDriver name" % driver_name) self._info("Creating an instance of the %s WebDriver" % driver_name) driver = creation_func(**init_kwargs) self._debug("Created %s WebDriver instance with session id %s" % (driver_name, driver.session_id)) return self._cache.register(driver, alias)