![](/img/trans.png)
[英]How to select radio button in selenium webdriver ? dynamic select of radio button
[英]Select a PrimeFaces radio button with Selenium Webdriver
我正在嘗試編寫Selenium測試來選擇一個單選按鈕。 以下是'view Source'中的html。
<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()
但這些都不起作用。 我錯過了什么?
這就是我最終讓它工作的方式!!
driver.findElement(By.cssSelector("label[for='surveyForm\\:surveyUrlType\\:1']")).click()
嘗試
WebElement element = new WebDriverWait(Driver,30).until(ExpectedConditions.elementToBeClickable(By.id("surveyForm:surveyUrlType:1")));
element.click();
我在Java中有以下代碼
lst=driver.findElements(by_name("surveyForm:surveyUrlType"))
for(condition)
option.click()
在python中我用這種方式解決了問題:
lst=driver.find_elements_by_name("surveyForm:surveyUrlType")
for i in lst:
if(i.text=="Enter Survey")
i.click()
elif(i.text=="Upload Survey URLs")
i.click()
如果上面的人沒有幫助嘗試這個
driver.findElement(by_class_name("ui-radiobutton-icon ui-icon ui-icon-bullet")).click()
driver.findElement(by_class_name("ui-radiobutton-icon")).click()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.