【发布时间】:2018-12-18 15:00:26
【问题描述】:
我正在尝试编写 Selenium 库扩展来简化一些事情,但我碰壁了。这是我的 python 类:
import uuid
import time
import re
from robot.api.deco import keyword
from robot.libraries.BuiltIn import BuiltIn
from SeleniumLibrary import SeleniumLibrary
class MySeleniumLibrary(SeleniumLibrary):
# def __init__(self):
# BuiltIn().set_library_search_order(self, "SeleniumLibrary")
@keyword('Select Checkbox')
def select_checkbox(self, locator):
self.wait_until_page_contains_element(locator)
elementId = self.get_element_attribute(locator,"id")
if elementId=='':
elementId = uuid.uuid4()
self.assign_id_to_element(locator, elementId)
self.execute_javascript('$("#' + elementId + ':not(:checked)").click();')
当我运行测试时,它会在构建库时抱怨:
Creating keyword 'Select Checkbox' failed: Keyword with same name defined multiple times.
然后在尝试选中复选框时最终失败:
Keyword with same name defined multiple times.
我的设置部分中只引用了 mySeleniumLibrary.py。我也尝试设置图书馆搜索顺序,但没有奏效。请问您有什么想法可以实现吗?
谢谢!
【问题讨论】:
-
Robot FW 用户指南建议阅读:Creating static keywords, What methods are considered keywords。
标签: python selenium robotframework