目前使用python2.7(请勿鄙视,公司环境,无法使用python3)+ robot framework,做功能测试的自动化。 今天需要使用selenium进行web页面的操作,记录如下
安装selenium2Library库
使用pip安装,过程是简单: pip install robotframework-selenium2Library
无头模式
其他的使用方式这里就不说了,只说怎么实现浏览器的无头模式
常用的Open Browser关键字,无法在本地实现无头模式(如果有错误,请指出),因为其最终调用的函数是
def _make_ff(self , remote , desired_capabilites , profile_dir):
if not profile_dir: profile_dir = FIREFOX_PROFILE_DIR
profile = webdriver.FirefoxProfile(profile_dir)
if remote:
browser = self._create_remote_web_driver(webdriver.DesiredCapabilities.FIREFOX ,
remote , desired_capabilites , profile)
else:
browser = webdriver.Firefox(firefox_profile=profile)
return browser
我们可以看到,对于本地浏览器来说,创建Firefox实例时,仅用了profile参数,无法将无头参数传入,因为无头参数需要在options或者firefox_options参数中传入。可以看下面Firefox对象的__init__函数:
<