我有以下问题:
所以,这是我的剧本:
Custom Select Checkbox id=my_checkbox #that works fine
Custom Select Checkbox customLocatorStrat #that doesn't work at all
*** Keywords ***
Custom Select Checkbox
[Arguments] ${locator} ${timeout}=${global_timeout}
Execute Javascript document.getElementById("${resultLocator}").checked = true;
OR
${el}.checked = true; #need to get the ${el} variable if the ${locator is not an id}
My Custom Locator
[Arguments] ${criteria} ${tag} ${constraints}
... #assembling xpath
${el}= Get Webelements xpath=${path}
[Return] ${el}
定位器策略没有问题 - 它工作正常。我只需要在我的自定义选择复选框关键字中使用它/强制它。我需要获取$ {el}变量,并考虑直接调用它的多个自定义定位器关键字对我不起作用。知道如何做到这一点好吗?非常感谢提前。
答案 0 :(得分:0)
selenium2library中的自定义定位器需要通过Add Location Strategy
[Doc]进行激活。在我看来,这似乎是你的例子中的缺失。
*** Test Cases ***
Test Case
Add Location Strategy custom Custom Locator Strategy
Page Should Contain Element custom=my_id
*** Keywords ***
Custom Locator Strategy
[Arguments] ${browser} ${criteria} ${tag} ${constraints}
${retVal}= Execute Javascript return
window.document.getElementById('${criteria}');
[Return] ${retVal}
答案 1 :(得分:-1)
${el}= Run Keyword If '${locator}'!='my_checkbox' My Custom Locator ${criteria} ${tag} ${constraints}
您可以在执行$ {el}之前获取变量.checked = true;