2016-05-20 15 views
0

idのチェックボックスを使ってページを削りたいのですが、それらの名前は同じで、値は異なっています。selenium webdriverを使用してチェックボックスを処理するにはどうすればよいですか?

<div class="mvNavLk"> 
    <form class="jsExpSCCategories" method="post" name="ExpressSCCategories" action="actionTest.html"> 
     <ul class="mvSrcLk"> 
      <li> 
       <label class="mvNavSel mvNavLvl1"> 
        First 
        <input type="checkbox" value="firstValue" name="selectedNavigationCategoryPath"> 
       </label> 
      </li> 
      <li> 
       <label class="mvNavSel mvNavLvl1"> 
        Second 
        <input type="checkbox" value="secondValue" name="selectedNavigationCategoryPath"> 
       </label> 
      </li> 
     </ul> 
    </form> 
</div> 
+0

何を設定しますか?どの要素にアクセスしたいですか? – theRoot

+0

@theRoot私は、値を設定するか、値firstValueを持つチェックボックスをクリックしたい – parik

+0

のチェックボックスで "firstValue"の値を設定したい –

答えて

1

使用:これは動作します

driver.find_element_by_css_selector(".mvSrcLk>li:nth-child(1)>label.mvNavSel.mvNavLvl1").click(); 

希望。

+0

私のコードで私の質問を更新、それは動作しません – parik

+1

私は私の答えを更新、plsは、 。 – noor

+0

ありがとう、それは機能するので、私たちは価値を持てる必要はありませんか? – parik

0
driver.findElement(By.name("selectedNavigationCategoryPath")).click(); 
+0

、リストJavaですべてのものを取ってそれぞれの値にインデックス値を与え、Javaのインデックスにフォームを開始しますElementNotVisibleExceptionは:メッセージ:要素が現在表示されていないので、私は私の答えを更新しましたHi – parik

1

こんにちはこの例はJavaである下記の注意事項のようにそれを行ってください

// take check boxes with same name inside the list 
List<WebElement> myCheckBox = driver.findElements(By.name("selectedNavigationCategoryPath")); 

// now on the basis of index call click 

myCheckBox.get(0).click(); // for the first check box 
Thread.sleep(2000); 
myCheckBox.get(1).click(); // for the second check box 

か、

driver.findElement(By.xpath("//*[@value='firstValue']")).click(); // for the 1st one 
Thread.sleep(2000); 
driver.findElement(By.xpath("//*[@value='secondValue']")).click(); // for the 2st one 

その値に基づいて選択したい場合更新

WebDriverWait wait = new WebDriverWait(driver,30); 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@value='firstValue']"))); 
driver.findElement(By.xpath("//*[@value='firstValue']")).click(); // for the 1st one 

希望これは、あなたが希望

+0

を持っているので、私は最初のリストにそれを取った理由は、チェックボックスの数、 – parik

+0

を持っていけない、動作しない –

+0

に私はこのエラーを得ているため、0でありますplzは私はあなたの提案を含め、サイトの名前と私のコードで私の質問を更新し、エラー – parik

0
Below Code is in C#, Collects all the Checkboxes with the name specified. Then Iterates through each ckeckbox, gets the value attribute, if the attribute is equal to your specified check box, then clicks it and comes out of the loop. Hope this should work. 
IList<IWebElement> myCheckBoxs = driver.FindElements(By.name("selectedNavigationCategoryPath")); 

Foreach(IWebElement chkBx in myCheckBoxs) 
{ 
    if(chkBx.GetAttribute("Value")=="Your Desired value") 
    { 
    chkBx.Click(); 
    break; 
    } 
} 

`

1

役立ちますこれは

driver.FindElement(By.XPath(".//label[contains(text(),'First')]/input")).SendKeys("test"); 
0

使用このCSSロケータをWORKS-。コードの下

[name='selectedNavigationCategoryPath'][value='firstValue'] 
関連する問題