[英]How do I determine radio button selection based on value using selenium webdriver?
I am trying to determine which of two radio buttons is selected and based on that select the other one. 我试图确定两个单选按钮中的哪个被选中,并根据该选择另一个按钮。 I'm using Java and selenium.
我正在使用Java和Selenium。
My HTML is: 我的HTML是:
<div class="row span-670px">
<h3>Turn on</h3>
<div class="field-row">
<div class="field-wrap radio-row clearfix ">
<input type="radio" name="choosePaymentModel" value="QUOTEHOLD" checked="checked" />
<label>
...
</label>
</div>
</div>
<div class="row last span-670px">
<h3>Turn off</h3>
<div class="field-row">
<div class="field-wrap radio-row clearfix ">
<input type="radio" name="choosePaymentModel" value="BASIC" />
<label>
...
</span>
</label>
</div>
</div>
The only thing that differs is the value attribute. 唯一不同的是value属性。 The checked attribute will change based on which one is checked, so the only clear way to differentiate the two is by value.
被选中的属性将根据被选中的属性而改变,因此区分两者的唯一明确方法是按值。 I can't seem to find the proper syntax to grab the correct radio buttons.
我似乎找不到正确的语法来获取正确的单选按钮。 When utilizing the IDE, the element identifiers swap out with each other depending on the selection so nothing is every unique.
在使用IDE时,元素标识符会根据选择相互交换,因此没有什么是唯一的。
Suggestions? 有什么建议吗?
I had to use: 我不得不使用:
element = driver.findElement(By.xpath("//input[@name='choosePaymentModel' and @value='QUOTEHOLD']"));
and 和
element = driver.findElement(By.xpath("//input[@name='choosePaymentModel' and @value='BASIC']"));
to determine which was selected, but unfortunately the click methods did not work on them. 确定选择了哪个,但不幸的是,单击方法不适用于它们。
When playing with the IDE was lucky enough to find two separately bizzare elements to click on, which were not in fact elements that contained the "isSelected" values. 使用IDE时,很幸运能够找到两个单独的bizzare元素以供单击,实际上这不是包含“ isSelected”值的元素。
In either case, looks like I found the answer to my own problem. 无论哪种情况,看起来我都找到了解决自己问题的答案。
String tempvalue[]=object.split(Concrete.VALUE_SPLIT);
//here I am splitting the values passed through data sheet against radio buttons
String Val_radio =Browser.driver.findElement(By.xpath(OR.getProperty(tempvalue[0])+data+OR.getProperty(tempvalue[1]))).getAttribute("value");
System.out.println(Val_radio);
Boolean radio = Browser.driver.findElement(By.xpath("//input[@name='radio' and @value="+"'"+Val_radio+"'"+"]")).isSelected();
if(radio.booleanValue()==true){
//do something here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.