无法在python中创建web驱动程序实例

2024-04-23 22:59:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用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”)中,我收到以下错误:

^{pr2}$

有人能帮我解决这个错误吗


Tags: 实例instance代码fromimportwebget错误
2条回答

错误消息告诉您,除非您实际运行的是测试(通过pybot、jybot等),否则不能使用内置库的方法。不能在独立的python脚本中调用BuiltIn().get_library_instance('Selenium2Library')。在

_current_browser只返回当前浏览器

如果你想在python中使用Selenium2Library,那么你可以做下一步

from Selenium2Library import Selenium2Library
sl = Selenium2Library()
sl.open_browser('firefox')

相关问题 更多 >