简体   繁体   中英

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). 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.

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.

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM