0

我试图确定选择了两个单选按钮中的哪一个,并基于该选择另一个。我正在使用Java和硒。

我的 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>

唯一不同的是 value 属性。选中的属性将根据选中的属性而改变,因此区分两者的唯一明确方法是通过值。我似乎找不到正确的语法来获取正确的单选按钮。在使用 IDE 时,元素标识符会根据选择相互交换,因此没有什么是唯一的。

建议?

4

2 回答 2

0

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.

In either case, looks like I found the answer to my own problem.

于 2012-11-14T15:40:24.630 回答
0
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

}
于 2013-07-19T02:10:04.487 回答