[英]close the window popup using JS
用於關閉窗口的編寫腳本,例如,在任何網站中我都會彈出該腳本
如果您啟動www.myntra.com,則會顯示一個窗口,例如您是否具有Facebook帳戶登錄。正在嘗試關閉此Facebook窗口
HTML code:
<div class="close"></div>
frist i have tried normal webdriver script
driver.findElement(By.xpath("//div[@class='close']").click;
above code gives me exception like "element is not visible you may want to interact with"
i have tried using javaexecutor somthing like below'
WebElement element = driver.findElement(By.xpath("//div[@class='close']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
above JS code doesnot give me exception but`enter code here` even it doesnot close the window for which i have written the code.
1)why in above webdriver code i get exception like "element is not visible you may want to interact with"? what is reason behind this.
2) what is the way to close the window?
我花了整整一整天,但有解決方案,請提前幫助我
您可以使用Selenium(不使用Javascript)關閉瀏覽器窗口。
// get the current windowHandle before triggering the popup (if loading myntra triggers the popup, just navigate to localhost and get the windowHandle there, before navigating to myntra)
String window1 = driver.getWindowHandle();
// trigger the popup
driver.get("www.myntra.com");
// get all window handles
String[] handles = driver.getWindowHandles().toArray(new String[2]);
// switch focus to the popup window
driver.switchTo().window(handles[handles.length - 1]);
// close the popup
driver.close();
// switch focus back to the original window
driver.switchTo().window(window1);
// continue test...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.