简体   繁体   English

如何使用Selenium Webdriver基于值确定单选按钮选择?

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

相关问题 在Java中使用Selenium WebDriver确定单选按钮值 - Determining Radio Button Value Using Selenium WebDriver in Java 如何使用 selenium webdriver 在 JQGrid 中选择单选按钮 - How to select Radio button in JQGrid using selenium webdriver 如何使用带有Java的Selenium WebDriver选择单选按钮? - How to select radio button using Selenium WebDriver with Java? 如何使用 Selenium WebDriver 读取 ::after 单选按钮元素的属性 - How to read ::after attributes of a radio button element using Selenium WebDriver 如何通过不使用x路径来选择Selenium Webdriver中的单选按钮 - how to select radio button in selenium webdriver by not using x path 如何使用 selenium 单击带有动态输入的单选按钮? - How do I click on radio button with dynamic input using selenium? 如何使用Selenium WebDriver检查单选按钮? - How to check a radio button with Selenium WebDriver? 如何检查单选按钮是否在 Selenium WebDriver 中被选中? - How to check if the radio button is selected or not in Selenium WebDriver? 如何在Selenium Webdriver中选择单选按钮? 动态选择单选按钮 - How to select radio button in selenium webdriver ? dynamic select of radio button 我如何确保从单选按钮组中选择单选按钮会影响其他单选按钮组中单选按钮的选择。 - How do i ensure that the selection of a radio button from a radio group affects the selection of a radio button in a different radio group.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM