2017-05-22 5 views
-1

「x」ボタンをクリックしてYoutubeポップアップウィンドウを閉じようとしましたが、次のエラーメッセージが表示されます。 org.openqa.selenium.ElementNotVisibleException:によって引き起こさ「x」をクリックしてYouTubeポップアップウィンドウを閉じるには、Selenium WebDriverを使用していません。

の要素は、現在表示されていない あるので、蛇腹コード試み

と相互作用しなくてもよい。

driver.findElement(By.className("close")).click(); 
driver.findElement(By.xpath("//button[@class='close']")).click(); 
driver.findElement(By.cssSelector("button[class='close']")).click(); 
JavascriptExecutor executor = (JavascriptExecutor) driver; 
executor.executeScript("arguments[0].click();", 
driver.findElement(By.className("close"))); 

HTML:

<div id="videoModal" class="modal fade in" aria-hidden="true" aria-labelledby="videoModal" role="dialog" tabindex="-1" style="display: block;"> 
<div class="modal-dialog"> 
<div class="modal-content"> 
<div class="modal-body"> 
<button class="close" aria-hidden="true" data-dismiss="modal" type="button">×</button> 
<div> 
<iframe width="100%" height="350" allowfullscreen="" src="https://www.youtube.com/embed/SQFKxxKMIxc?autoplay=1"/> 
</div> 

スクリーンショット: https://i.stack.imgur.com/W3IXe.png

public Boolean closeVideoPopup(){ 
    try{ 
     driver.findElement(By.id("video-how-to")).click(); 
     driver.waitForPageLoad(); 
     driver.findElement(By.className("close")).click(); 
     return true; 
    } 
    catch(Exception e) { 
     logger.info("Exception occurred: "+ e.getMessage().toString().substring(0, Integer.parseInt(TestConstants.ERRCHARCOUNT))); 
    } 
    return false; 
} 
+0

をクリックしましょう**は私たちにどのを示す考えることができます'x'ボタン**あなたはあなたの作品の一部を参考にしてくれていますか?ありがとう – DebanjanB

+0

@AakashSinghあなたがクリックしようとしている** x **を '検査した後に、ポップアップの印刷画面を追加することもできます。 – iamdanchiv

+0

@Devスクリーンショットのリンクと私が書いたコードを追加しました。 –

答えて

0

それは今Sikuliを使用してこれを行うには

driver.findElement(By.xpath(".//*[@id='videoModal']/div/div/div/button[@class='close']")).click(); 

手順完全なXPathを使用して動作します:プロジェクトでSikuli jarファイルを追加するかのpom.xml

で依存関係として追加

<dependency> 
      <groupId>com.sikulix</groupId> 
      <artifactId>sikulixapi</artifactId> 
      <version>1.1.0</version> 
</dependency> 

Sikuli IDEを使用して要素のスクリーンショットを撮ります。 Sikuli IDEをインストールして使用する 手順: http://www.sikuli.org/downloadrc3.html

以下のコードを書く:Screenクラスの

Screen screen = new Screen(); 
Pattern image = new Pattern(filePath\\xbutton.png"); 
screen.click(image); 

クリックメソッドは要素

+0

ビジュアルオートメーションには、[Kantu Web Automation](https://a9t9.com/kantu/web-automation)もあります。これはSikuliと同じように機能しますが、Google Chromium(デスクトップ全体ではありません)を自動化します。フレーム/ iframeのあるサイトでうまく動作します。 – Tienkamp

0

このセレクタは動作するはずですが、あなたはあなたに適したマークアップに置き換える場合は、より効率的になります。

driver.findElement(By.xpath("//*[contains(@class, 'close')]")); 

または、si私たちは、求められている要素がdivであることを知っています:

driver.findElement(By.xpath("//div[contains(@class, 'close')]")); 

希望すると助かります。

+0

試しました。しかし、それは動作しませんでした。 –

0

他の要素がポップアップと重なっていることがあります。したがって、要素が可視になるために、要素を明示的に待機することができます。

WebDriverWait wait=new WebDriverWait(driver, 90); 
wait.untill(ExpectedConditions.visibilityOf(driver.findElement(By.className("close"))); 

...オーバーラップしている要素を見つけて、要素が消えるのを待ちます。

両方の方法でお試しいただけます。

+0

試しました。しかし、それは動作しませんでした。 –

関連する問題