2013-12-17 13 views
7

ラジオボタンを選択するために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> 

「アンケートURLのアップロード」ラジオボタンを選択します。

私はラジオボタンを選択するためにいくつかの異なる方法を試しました。

 $("#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() 

しかし、これらの作業はありません。私は何が欠けていますか?

+0

「プライムフェイス」ダイアログにあります。私はページ上の他の入力ボックスにアクセスしてその値を操作することができます。しかし、このラジオボタンだけ。最初のものがあらかじめ選択されています。私は第2のものを選択したい。いいえ、私はWebDriverWaitを試していません。 – user1860447

答えて

6

これは私が最終的に動作させる方法です!

driver.findElement(By.cssSelector("label[for='surveyForm\\:surveyUrlType\\:1']")).click() 
+0

'label'をクリックしたようなコードで、' input'ではなく、実際には動くのですか? –

+0

@vincebowdenはい、 'label'にはonclickリスナーがあります。失敗しましたが、ラベルをクリックすると、Selenium 2.47.1とPrime 5.2 – peater

0

私はこの方法上記の問題解決私は、Java

で次のコードはPythonで
lst=driver.findElements(by_name("surveyForm:surveyUrlType")) 
    for(condition) 
     option.click() 

を持って

WebElement element = new WebDriverWait(Driver,30).until(ExpectedConditions.elementToBeClickable(By.id("surveyForm:surveyUrlType:1"))); 
element.click(); 
+0

お返事ありがとうございます。私はそれを試して、私はこのエラーが表示されます:org.openqa.selenium.WebDriverException:不明なエラー:要素はポイント(454,255)でクリック可能ではありません。他の要素はクリックを受け取ります:

...
(セッション情報:chrome = 31.0.1650.63) (ドライバ情報:chromedriver = 2.1、プラットフォーム= Mac OS X 10.8.5 x86_64)(警告:サーバはスタックトレース情報を提供しませんでした) – user1860447

0

を試してみてください:上記のいずれかがいない場合は

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() 
+0

お返事ありがとうございます。私はすべての提案を試み、彼らは動作しませんでした。 : – user1860447

関連する問題