英文:
Robot Framework: How to access a class property from a Robot Framework library
问题
To implement a custom function, I am trying to access the driver
property from the SeleniumLibrary
which looks like below in the python package:
class SeleniumLibrary(DynamicCore):
ROBOT_LIBRARY_SCOPE = "GLOBAL"
ROBOT_LIBRARY_VERSION = __version__
@property
def driver(self) -> WebDriver:
"""Current active driver.
:rtype: selenium.webdriver.remote.webdriver.WebDriver
:raises SeleniumLibrary.errors.NoOpenBrowser: If browser is not open.
"""
if not self._drivers.current:
raise NoOpenBrowser("No browser is open.")
return self._drivers.current
I have created the webdriver using the Open Browser
command like Open Browser url=${url} browser=${browser} alias=Test options=${options} executable_path=${driverPath}
.
I have tried multiple commands in the robot script to access the @property
driver
but it is not working:
Log ${SeleniumLibrary.driver}
${driver}= SeleniumLibrary.driver
${driver}= Evaluate SeleniumLibrary.driver
Error Message: Evaluating expression 'SeleniumLibrary.driver' failed: AttributeError: module 'SeleniumLibrary' has no attribute 'driver'
Reference: https://github.com/robotframework/SeleniumLibrary/blob/master/docs/extending/extending.rst#id14
英文:
To implement a custom function, I am trying to access the driver
property from the SeleniumLibary
which looks like below in the python package:
class SeleniumLibrary(DynamicCore):
ROBOT_LIBRARY_SCOPE = "GLOBAL"
ROBOT_LIBRARY_VERSION = __version__
@property
def driver(self) -> WebDriver:
"""Current active driver.
:rtype: selenium.webdriver.remote.webdriver.WebDriver
:raises SeleniumLibrary.errors.NoOpenBrowser: If browser is not open.
"""
if not self._drivers.current:
raise NoOpenBrowser("No browser is open.")
return self._drivers.current
I have create the webdriver using the Open Browser
command like Open Browser url=${url} browser=${browser} alias=Test options=${options} executable_path=${driverPath}
.
I have tried multiple commands in the robot script to access the @property
driver
but it is not working:
Log ${SeleniumLibrary.driver}
${driver}= SeleniumLibrary.driver
${driver}= Evaluate SeleniumLibrary.driver
Error Message: Evaluating expression 'SeleniumLibrary.driver' failed: AttributeError: module 'SeleniumLibrary' has no attribute 'driver'
Reference: https://github.com/robotframework/SeleniumLibrary/blob/master/docs/extending/extending.rst#id14
答案1
得分: 1
我能够使用Robot Framework找到解决方案。
${SeleniumLibrary} Get Library Instance SeleniumLibrary
${driver}= Set Variable ${SeleniumLibrary.driver}
英文:
I was able to find the solution using Robot Framework.
${SeleniumLibrary} Get Library Instance SeleniumLibrary
${driver}= Set Variable ${SeleniumLibrary.driver}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论