Robotframework - 如何通过关联标签中的文本 select 这种类型的单选按钮?
Robotframework - How can I select this type of radio button by means of the text in its associated label?
我无法编写 task/keyword 可以 select 这种类型的单选按钮通过其关联的文本标签。在这种特定情况下:common-response-headers-policy-v1.0.0
使用的库:SeleniumLibrary 4.4.0
期望的行为:单击元素 或 Select 单选按钮
<div style="width:96%; display: flex">
<div class="radio template-radio ng-scope" tooltip="" tooltip-trigger="mouseenter" tooltip-placement="top" style="max-width: 100%"><input id="45725" type="radio" ng-model="$parent.$parent.selectedPolicyTemplate" value="45725" ng-disabled="!templateCanBeApplied(template)" required="required" class="ng-untouched ng-dirty ng-valid-parse ng-valid ng-valid-required" name="1464">
<label class="policy-name ng-binding" for="45725" data-test-id="policy-template-name" ng-style="{'max-width': template.custom ? '80%' : '100%'}" ng-class="{'text-disabled': !templateCanBeApplied(template)}" title="common-response-headers-policy-v1.0.0" style="max-width: 80%;">common-response-headers-policy-v1.0.0</label><!-- ngIf: template.custom -->
<span ng-if="template.custom" class="label label-default ng-scope" style="margin-left: 4px">Custom</span><!-- end ngIf: template.custom -->
</div>
<div style="width:2%"><i class="fa fa-info-circle info-icon ng-scope" style="margin-left: 4px; margin-top: 8px" tooltip="Initialize response headers data in session variables" tooltip-trigger="mouseenter" tooltip-placement="bottom"></i></div></div>
这是视觉参考。
有人可以帮我解决这个问题吗?提前谢谢你
假设您使用 Selenium2Library
并且您想要单击(使用 Get WebElement
否则)您可以使用的元素:
Click Element //input[@type="radio"][following-sibling::label[1][.="common-response-headers-policy-v1.0.0"]]
查找紧跟特定同级元素的 input
元素(label
元素的内容等于“common...”)。
旧语法:
Click Element xpath: //input[@type="radio"][following-sibling::label[1][.="common-response-headers-policy-v1.0.0"]]
编辑:如果遇到异常错误,请在点击前添加预期条件:
Wait Until Element Is Enabled xpath: //input[@type="radio"][following-sibling::label[1][.="common-response-headers-policy-v1.0.0"]]
这是我的问题的解决方案
Wait Until Element is Enabled //*[@class="modal-body ap-resource-level-policies ng-scope"]
${for_value}= Get Element Attribute //label[@title="common-response-headers-policy-v1.0.0"] for
Execute Javascript document.getElementById("${for_value}").click()
希望对大家有所帮助。干杯
我无法编写 task/keyword 可以 select 这种类型的单选按钮通过其关联的文本标签。在这种特定情况下:common-response-headers-policy-v1.0.0
使用的库:SeleniumLibrary 4.4.0
期望的行为:单击元素 或 Select 单选按钮
<div style="width:96%; display: flex">
<div class="radio template-radio ng-scope" tooltip="" tooltip-trigger="mouseenter" tooltip-placement="top" style="max-width: 100%"><input id="45725" type="radio" ng-model="$parent.$parent.selectedPolicyTemplate" value="45725" ng-disabled="!templateCanBeApplied(template)" required="required" class="ng-untouched ng-dirty ng-valid-parse ng-valid ng-valid-required" name="1464">
<label class="policy-name ng-binding" for="45725" data-test-id="policy-template-name" ng-style="{'max-width': template.custom ? '80%' : '100%'}" ng-class="{'text-disabled': !templateCanBeApplied(template)}" title="common-response-headers-policy-v1.0.0" style="max-width: 80%;">common-response-headers-policy-v1.0.0</label><!-- ngIf: template.custom -->
<span ng-if="template.custom" class="label label-default ng-scope" style="margin-left: 4px">Custom</span><!-- end ngIf: template.custom -->
</div>
<div style="width:2%"><i class="fa fa-info-circle info-icon ng-scope" style="margin-left: 4px; margin-top: 8px" tooltip="Initialize response headers data in session variables" tooltip-trigger="mouseenter" tooltip-placement="bottom"></i></div></div>
这是视觉参考。
有人可以帮我解决这个问题吗?提前谢谢你
假设您使用 Selenium2Library
并且您想要单击(使用 Get WebElement
否则)您可以使用的元素:
Click Element //input[@type="radio"][following-sibling::label[1][.="common-response-headers-policy-v1.0.0"]]
查找紧跟特定同级元素的 input
元素(label
元素的内容等于“common...”)。
旧语法:
Click Element xpath: //input[@type="radio"][following-sibling::label[1][.="common-response-headers-policy-v1.0.0"]]
编辑:如果遇到异常错误,请在点击前添加预期条件:
Wait Until Element Is Enabled xpath: //input[@type="radio"][following-sibling::label[1][.="common-response-headers-policy-v1.0.0"]]
这是我的问题的解决方案
Wait Until Element is Enabled //*[@class="modal-body ap-resource-level-policies ng-scope"]
${for_value}= Get Element Attribute //label[@title="common-response-headers-policy-v1.0.0"] for
Execute Javascript document.getElementById("${for_value}").click()
希望对大家有所帮助。干杯