2017-09-16 12 views
0

こんにちはみんな大丈夫ですので、私は明らかに尋ねている場合は、セレン/ Java/HTMLに相対的な(読んで:完全な)初心者です。セレンは特定のチェックボックスをクリックできません

:特定のチェックボックス2がチェックされている場合 何に必要なのはそれをここで

をオフにし、

  1. 特定のチェックボックス1をクリックし、
  2. にできるようにするWebサイトのHTMLです特定チェックボックス1

    <div class="checkbox"> 
        <label id="agree_to_terms_label" for="agree_to_terms_join" class="visible"> 
         <input id="agree_to_terms_join" name="agree_to_terms" type="checkbox" data-required="true" data-required-message="You need to agree to the *** Account Holder agreement" data-change="" class="parsley-validated"> 
         <span class="left-block"></span> 
         I have read, understand and agree to the <a href="/terms-and-conditions/" target="_blank">*** Account Holder Agreement</a> 
         and acknowledge <a href="/privacy-policy" target="_blank">*** Privacy Policy</a> 
         <input type="hidden" name="agree_to_terms" value="yes"> 
        </label> 
        </div> 
    

    特定のチェックボックス2:

    <div class="checkbox"> 
        <label id="agree_to_offers_label" for="agree_to_offers" class="visible"> 
         <span class="left-block"> 
         <input id="agree_to_offers" name="agree_to_offers" type="checkbox" data-required-message="" data-change="" checked="checked" value="yes"> 
         <span>By joining *** you'll be notified of exclusive offers and account updates via email</span> 
         </span> 
        </label> 
        </div> 
    

    マイ無益試み:

    のXpath:

    driver.findElement(By.xpath("//input[@id='agree_to_terms_join' and @type='checkbox']")).click(); 
    

    要素DIV代わり

    driver.findElement(By.xpath("//*[@id='agree_to_terms_label']/input")).click(); 
    
    内のHREFハイパーリンクに見えない

    driver.findElement(By.xpath("//*[@id='agree_to_terms_join']/parent::label")).click(); 
    

    クリック

    要素は見えない

    CSS:

    driver.findElement(By.cssSelector("input[id = 'agree_to_terms_join'][type = 'checkbox']")).click(); 
    

    要素は見えない

    by.className:

    driver.findElement(By.className("checkbox")).click(); 
    

    が開き、ハイパーリンク

    は、私は、フォーラムの周りを見ていましたとの言及を見た要素は隠されています - しかし、私は何かを見つけることができませんiframeやその他のものは、隠れているように見えますか?

    ご協力いただければ幸いです!

+0

フレーム – iamsankalp89

+0

こんにちは、私は、フレームをチェックしているかどうか確認してくださいについては、以下のコードは動作するはずですが、1つがあるようにそれは見えません。 – KZNKatana

+0

URLを共有できます – iamsankalp89

答えて

0

試してみるには、以下の

WebDriver driver=new FirefoxDriver(); 
driver.manage().window().maximize(); 
driver.get("https://www.quidco.com/join-quidco/");   
driver.findElement(By.xpath(".//label[@id='agree_to_terms_label']")).click();   
driver.findElement(By.xpath(".//label[@id='agree_to_offers_label']")).click(); 

場合:

WebElement yourChkBox = driver.findElement(By.xpath("//*[@id='agree_to_terms_join']/parent::label")); 

WebDriverWait wait = new WebDriverWait(driver, 20); 
wait.until(ExpectedConditions.visibilityOf(yourChkBox)); 

Actions act = new Actions(driver); 
act.moveToElement(yourChkBox).click().build().perform(); 

UPDATE:

OR以下のようにjavascriptexecutor使用してみてください:

WebElement yourChkBox = driver.findElement(By.xpath("//*[@id='agree_to_terms_join']/parent::label")); 

JavascriptExecutor js = (JavascriptExecutor) driver;   
js.executeScript("arguments[0].setAttribute('value', 'Yes');", yourChkBox ); 
+0

@And( "^ Check the relevant boxes $") \t public voidチェックボックス(){ \t \t \t \t //driver.findElement(By.xpath( ".// label [@ id = 'agree_to_terms_label']"))。 \t \t \t \t WebElement yourChkBox = driver.findElement(By.xpath( "// * [@ id = 'agree_to_terms_join']/parent :: label")); \t \t WebDriverWait wait = new WebDriverWait(driver、60); wait.until(ExpectedConditions.visibilityOf(yourChkBox)); \t \tアクションact = new Actions(driver); act.moveToElement(yourChkBox).click()。build()。perform(); \t \t} – KZNKatana

+0

しかし、私はまだチェックボックスをクリックすることはできません - ハイパーリンクは代わりに開いています。私が間違っていることを確認していない! – KZNKatana

+0

@KZNKatana:更新された部分を試してください – kushal

0

これを試してみてください:必要プット暗黙的または明示的な待機

+0

私はまだ別の理由で表示されていないようですちょうどそれらを試してみました - 私は恐れています:( – KZNKatana

+0

待ちます私は試してみます – iamsankalp89

+0

それは試してみましたが、その代わりにそのdivクラスのハイパーリンクを開きますが、私はチェックボックスを選択しようとしています...私はまた、私は何か間違っていますか? – KZNKatana

1

クリックする正確な要素は、擬似要素である「:: before」です。私はあなたがJavascriptを使用する必要があると思います。あなたは

WebElement element1 = driver.findElement(By.cssSelector(".left-block")); 
JavascriptExecutor executor = (JavascriptExecutor)driver; 
executor.executeScript("arguments[0].click();", element1); 
+0

あなたは絶対星です - これは動作します!しかし、Web htmlには2つの.left-blockクラスがあります.Seleniumにどのようなものを指定するように頼むことができますか?だから、私は特定のチェックボックス1(私の元の質問で)*チェックボックス2(それが意味をなさない?)を選択するだけです。 – KZNKatana

+0

ありがとうございました。インデックスはいつでも指定できます。 WebElement element1 = driver.findElement(By.cssSelector( "。left-block")[Index]); 'indexは1から始まります。 – Kapil

+0

良い仕事があります:)) – iamsankalp89