[英]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.