我正在尝试使用以下代码在python中创建一个web驱动程序实例:
from robot.libraries.BuiltIn import BuiltIn
import Selenium2Library
from Selenium2Library import Selenium2Library
def get_webdriver_instance():
s2l = BuiltIn().get_library_instance("Selenium2Library")
return s2l._current_browser()
但在BuiltIn().get_library_instance("Selenium2Library")上,我得到了以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 2922, in get_library_instance
return self._namespace.get_library_instance(name)
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 70, in _namespace
return self._context.namespace
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 65, in _context
raise RobotNotRunningError('Cannot access execution context')
robot.libraries.BuiltIn.RobotNotRunningError: Cannot access execution context
有没有人可以帮我解决这个错误
发布于 2015-07-28 14:16:01
错误消息告诉你不能使用BuiltIn库的方法,除非你真的在运行一个测试(通过pybot、jybot等)。不能在独立的python脚本中调用BuiltIn().get_library_instance('Selenium2Library')
。
发布于 2015-07-28 13:57:35
_current_browser
是只返回当前浏览器的
如果您想在python中使用Selenium2Library,那么您可以执行下一步
from Selenium2Library import Selenium2Library
sl = Selenium2Library()
sl.open_browser('firefox')
https://stackoverflow.com/questions/31674577
复制相似问题