无法单击Web UI页面上单选按钮更改顺序的单选按钮Selenium Web Driver Java

时间:2018-09-26 22:52:39

标签: java html selenium-webdriver

我正在尝试单击单选按钮,该按钮会更改ui页面上的顺序。但是,有一件事已经解决,我要单击的单选按钮位于文本EXPLAIN

旁边

以下是网页HTML:

"Reissue ID Card"

我正在使用从HTML上方创建的以下xpath,但没有运气:

<tbody>
<tr class="gridcell">
<tr class="gridcell">
<tr class="gridcell">
<td valign="bottom" style="border-right: 1px solid rgb(160, 160, 160);">
<td width="51" align="center" style="width:46px;">
<input id="rdbSelectAction" type="radio" onclick="fnRowSelected(this);" value="37089~8/8/2018 12:00:00 AM" name="rdbSelectAction" oldchecked="false">
</td>
<td width="140"> Reissue ID Card </td>
<td width="82"> 8/6/2012 8:07:15 AM </td>
<td width="82"> 8/8/2018 12:00:00 AM </td>
<td width="89"> Directory 2018 </td>
<td width="94"> Closed Unsuccessful - Need to Reissue ID Card Closed Unsucc </td>
<td width="103"> Admin </td>
<td width="78"> 6578 </td>
<td width="129"> 91890 </td>
<td width="330"> 000004503701/01/2012 </td>

2 个答案:

答案 0 :(得分:0)

将您的元素存储在列表中,找到一个完美匹配,然后单击您的元素。

 WebElement radioButton = driver.findElement(By.Xpath("Your Xpath"));
    String radioButtonName = "Reissue ID Card";
    List<WebElement> listRadioButton = driver.findElements(radioButton);
                System.out.println("List of Radio Buttons are available " + listRadioButton);
                Iterator<WebElement> iter = listRadioButton.iterator();
                System.out.println("Iterator Print" + iter);
                while (iter.hasNext()) {
                    WebElement we = iter.next();
                    System.out.println("Web Element We " + we.getText());
                    if (we.getText().equals(radioButtonName)) {
                        we.click();
                    }
                }

答案 1 :(得分:0)

我从上述问题中的HTML中创建了以下xpath,并且可以单击动态位置更改单选按钮。

//tbody/tr/td[contains(text(),'Reissue ID Card')]/preceding-sibling::td[1]/*[@id='rdbSelectAction']