我正在尝试编写Selenium测试来选择一个单选按钮。以下是来自'查看源代码'的html。使用Selenium Webdriver选择PrimeFaces单选按钮
<table id="surveyForm:surveyUrlType" class="ui-selectoneradio ui-widget" style="width:100%;margin-top:10px;margin-bottom: 10px;">
<tbody>
<tr>
<td>
<div class="ui-radiobutton ui-widget">
<div class="ui-helper-hidden-accessible">
<input id="surveyForm:surveyUrlType:0" name="surveyForm:surveyUrlType" type="radio" value="TYPED" checked="checked" onchange="com.ssi.feasibility.surveyView.showSurveyType(this);">
</div>
<div class="ui-radiobutton-box ui-widget ui-corner-all ui-state-default ui-state-active">
<span class="ui-radiobutton-icon ui-icon ui-icon-bullet"></span>
</div>
</div>
</td>
<td><label for="surveyForm:surveyUrlType:0">Enter Survey URL</label></td>
<td>
<div class="ui-radiobutton ui-widget">
<div class="ui-helper-hidden-accessible">
<input id="surveyForm:surveyUrlType:1" name="surveyForm:surveyUrlType" type="radio" value="FILE" onchange="com.ssi.feasibility.surveyView.showSurveyType(this);">
</div>
<div class="ui-radiobutton-box ui-widget ui-corner-all ui-state-default">
<span class="ui-radiobutton-icon"></span>
</div>
</div>
</td>
<td><label for="surveyForm:surveyUrlType:1">Upload Survey URLs</label></td>
</tr>
</tbody>
</table>
我想选择“上传调查网址”单选按钮。
我已经尝试了几种不同的方法来选择单选按钮。以下是几个:
$("#surveyForm\\surveyUrlType").click();
This gives me the error :
$("#surveyForm\\:surveyUrlType\\:1").first().click()
错误 - 元素在点(809,367)处不可点击。其他元素将收到点击:...
下面给我NoSuchElementFound:
driver.findElement(By.id("surveyForm:surveyUrlType:1")).click()
driver.findElement(By.xpath("//input[@type='radio' and @id='surveyForm\\:surveyUrlType\\:1']")).click()
driver.findElement(By.xpath("//input[@value='FILE']")).click()
driver.findElement(By.cssSelector("#surveyForm\\:surveyUrlType\\:1")).click()
下面不给我任何错误,但他们也没有选择的单选按钮。
$(".ui-radiobutton-box ui-widget ui-corner-all ui-state-default")[1].click()
$(".ui-radiobutton-box ui-widget ui-corner-all ui-state-default").click()
$("#surveyForm\\:surveyUrlType").find(".ui-radiobutton-box ui-widget ui-corner-all ui-state-default").find("span").click()
但是这些都没有工作。我错过了什么?
它在Primefaces对话框中。我可以访问页面上的其他输入框并操作它们的值。但只是这个单选按钮。第一个是预选的。我想选择第二个。不,我没有尝试过WebDriverWait。 – user1860447