简体   繁体   English

如何识别是否在硒中选中了单选按钮?

[英]How to identify if a radio button is checked in selenium?

I have below html code snippet for radio button .我有以下单选按钮的 html 代码片段。

 <label for="exceptionTrue">
    <span/>
    <span class="check" style="background: #F3565D;"/>
    <span class="box"/>
      Yes
    </label>

HTML displayed is the same if the radio button is selected or if not selected in the page.如果在页面中选中或未选中单选按钮,则显示的 HTML 是相同的。

Element is in span class='check' if the radio button is selected and is in span class='box if not selected.如果单选按钮被选中,则元素在 span class='check' 中,如果未选中,则元素在 span class='box 中。 Since the html code is present in page if the radio button is selected or not selected.So i cannot user verifying if class='check' .由于 html 代码存在于页面中,如果单选按钮被选中或未选中。所以我不能用户验证 class='check' 。 .Any idea how i can verify this...I have tried is.Selected and it doesn't work . 知道我如何验证这一点...我试过 is.Selected 但它不起作用

Well I don't see a problem here, you know how this radio button works and you just need to implement this verification.好吧,我在这里没有看到问题,您知道此单选按钮的工作原理,您只需要执行此验证即可。 Find your radio button element and than:找到您的单选按钮元素,然后:

if (element.getAttribute("class").equals("check")){ 
return true; }
else {
return false; }

This is just an example, you can adjust this to your code.这只是一个示例,您可以将其调整为您的代码。

EDIT: When I read your question again it's really unclear so I'm not sure if this helps.编辑:当我再次阅读您的问题时,它真的不清楚,所以我不确定这是否有帮助。 You need to provide more details on this.您需要提供更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当前无法识别列表中的“已检查/选定”单选按钮 - Unable to Identify presently the Checked/Selected radio button in a list 如何使用 Selenium 和 Java 识别是否选择了带有伪元素::after 样式的单选按钮选项 - How to identify if a radio button option styled with pseudo element ::after is selected or not using Selenium and Java 如果选中单选按钮,如何检查复选框 - How to check checkbox if radio button is checked 如何设置选中的单选按钮状态。 不使用广播组 - How to set checked radio button state . not using radio group 获取选中的单选按钮 - Get the checked radio button 如何在Selenium Webdriver中选择单选按钮? 动态选择单选按钮 - How to select radio button in selenium webdriver ? dynamic select of radio button 更改单选按钮选中状态时如何从单选按钮组中的单选按钮获取文本 - How to get the text from radio button in a radio group when radio button checked state is changed 如何在Android中的上一个按钮上设置选中的单选按钮? - How to set checked Radio Button on Previous Button in Android? 如何使用Selenium WebDriver检查单选按钮? - How to check a radio button with Selenium WebDriver? 如何使用 Selenium 单击单选按钮 - How to click on a radio button using Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM