【问题标题】:I am not able to click radiobuttons using Robot Framework.(and selenium2Library)我无法使用机器人框架单击单选按钮。(和 selenium2Library)
【发布时间】:2017-11-12 10:08:33
【问题描述】:

谁能帮帮我?

实际上,单选按钮始终在 DOM 中,但它们基于 ADDRESS 字段在页面上可见,因此您可以在下面看到 Pickup 和 Delivery 时区相同,然后单选按钮在页面上不可见:

但如果它们(取货和送货时区)不同,则 RADIO BUTTONS 可见,如下所示: 。

现在在我的脚本中,我尝试将所有单选按钮设置为 NO,因此当我运行它时,脚本通过但实际上单选按钮保持不变。结果是PASS如下图

脚本运行后的Chrome浏览器如下图所示:

这是我为等待和单击单选按钮编写的脚本:

`wait until element is enabled  id=exportclearance_1
  page should contain radio button  id=exportclearance_1
  click element  id=exportclearance_1
  click element  id=transitclearance_1
  click element  id=importclearance_1
  click element  id=insurance_1`

这是页面的 HTML:

`<div class="form-group">
<label class="col-sm-4 control-label" for="">
<div class="col-sm-6">
<input id="exportclearance_0" name="export_clearance" value="True" autocomplete="off" type="radio"/>
<label class="control-label control-label-light clearance" for="exportclearance_0">Yes</label>
<input id="exportclearance_1" name="export_clearance" value="False" autocomplete="off" type="radio"/>
<label class="control-label control-label-light clearance" for="exportclearance_1">No</label>
<br/>
</div>
</div>
<div id="exportclearance-textarea" style="display:none">
<div class="row col-sm-6 col-sm-offset-4">
<textarea id="field-exportclearance" class="form-control customs-field" cols="40" name="export_clearance_instructions" placeholder="Instructions for export clearance (E.g. Broker details, Customs number, etc.)" rows="2"/>
</div>
</div>
<div class="form-group">
<div id="transitclearance-textarea" style="display:none">
<div class="form-group">
<div id="importclearance-textarea" style="display:none">
</div>
<div class="form-group">
<div id="id_attachment_formset_parent">
<div class="form-group">
<di

`

【问题讨论】:

  • 您可以尝试点击标签是/否。它可能有效。
  • 如?我已经按照代码中的 id 点击了元素,所以id=exportclearance_1 表示我尝试点击“否”进行出口清关单选按钮。 @Murthi
  • 您正在点击输入标签,但我要求尝试使用标签标签。
  • “无法点击”是什么意思?看来您确实可以单击它们,因为您的脚本没有引发任何错误。您是否尝试过使用 Select Radio Button 关键字?
  • 是的,我确实尝试过select radio button export_clearance True,但这也没有用。 “无法单击”意味着尽管脚本没有抛出任何错误,但它没有单击提到的单选按钮(尽管我不确定为什么)。可能是脚本太快或其他原因,但我也尝试过 sleep 并等待元素,但没有运气。 @BryanOakley

标签: selenium xpath selenium-webdriver radio-button robotframework


【解决方案1】:

JavaScript 执行器为我工作,如下所示。

execute javascript document.getElementById('insurance_1').click()

【讨论】:

    猜你喜欢
    • 2020-02-07
    • 1970-01-01
    • 2017-11-14
    • 2022-10-16
    • 2020-10-07
    • 2017-06-25
    • 1970-01-01
    • 2018-07-15
    • 2021-12-21
    相关资源
    最近更新 更多