python selenium webdriver_Python selenium.webdriver 模块,Opera() 实例源码 - 编程字典

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%sWebDriver" % driver_name)

driver = creation_func(**init_kwargs)

self._debug("Created%sWebDriver instance with session id%s" % (driver_name, driver.session_id))

return self._cache.register(driver, alias)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值