简体   繁体   English

在Java中使用Selenium WebDriver确定单选按钮值

[英]Determining Radio Button Value Using Selenium WebDriver in Java

I want to know which of the two is radio buttons is selected and based on that select the other one. 我想知道选择了两个单选按钮中的哪个,并根据该选择选择另一个。 The test has to be able to run regardless of which radio button is selected. 无论选择哪个单选按钮,测试都必须能够运行。 I am creating this test with Selenium WebDriver in Java(Eclipse for IDE). 我正在用Java(Eclipse for IDE)中的Selenium WebDriver创建此测试。 From what I understand the only difference between the two is that their values change. 据我了解,两者之间的唯一区别是它们的价值在变化。 I am new to Selenium and Java so I want to understand why the solution is what it is. 我是Selenium和Java的新手,所以我想了解解决方案的实质。

The first radio button has a value of 1 and the second one has a value of 2. I know where they are but don't know exactly how to form this code. 第一个单选按钮的值为1,第二个单选按钮的值为2。我知道它们在哪里,但不确切知道如何形成此代码。

form method="POST" action="switch.do">
<table width="800" cellspacing="0px" cellpadding="7px" border="0">
<tbody>
   <tr>
   <tr>
   <tr class="oddRow">
      <td width="30px">
         <input type="radio" value="1" checked="" name="masterSelect">
      </td>
      <td>
      <td align="center">
      <td align="center">
      <td align="center">
      <td align="center">
   </tr>
   <tr class="evenRow">
      <td width="30px">
         <input type="radio" value="2" name="masterSelect"> 
      </td>

I also see an additional information. 我还看到了其他信息。 The checked radio just populates with checked="" attribute. 选中的单选仅填充有checked=""属性。 So, I would say find the element with value and use getAttribute() inside a try catch block to see if that attribute exist or not 因此,我想说的是找到具有值的元素,并在try catch块中使用getAttribute()来查看该属性是否存在

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

相关问题 单击与表单页面相对应的单选按钮的值-Java-Selenium Webdriver - Clicking on a value of the radio button in accordance with the sheet page - Java - Selenium Webdriver 在视野之外使用 selenium webdriver java 选择单选按钮 - Selecting a radio button using selenium webdriver java when out of view 如何使用带有Java的Selenium WebDriver选择单选按钮? - How to select radio button using Selenium WebDriver with Java? 使用带有Java的Selenium WebDriver在组中选择单选按钮 - Select Radio Button in a group using Selenium WebDriver with Java 选择Selenium Webdriver(Java)上的单选按钮 - Selecting Radio button on Selenium Webdriver (Java) 如何使用Selenium Webdriver基于值确定单选按钮选择? - How do I determine radio button selection based on value using selenium webdriver? 如何使用 java 在 selenium webdriver 中使用 select 单选按钮和复选框? - how to select radio button & checkbox in selenium webdriver with java? 如何使用 Selenium WebDriver 读取 ::after 单选按钮元素的属性 - How to read ::after attributes of a radio button element using Selenium WebDriver 在<label>使用Selenium WebDriver</label>的列表中找到选定的单选按钮 - Find the selected radio button in a list of <label> using selenium webdriver 为什么我没有使用selenium webdriver选择单选按钮? - Why am failing to select radio button using selenium webdriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM