check , whether it is separate window, if it it then will code might be work
private static Object Handle1;
private static Object Handle2;
public static void switchToWindowsPopup() {
Set<String> handles = DriverManager.getCurrent().getWindowHandles();
Iterator<String> itr = handles.iterator();
Handle1 = itr.next();
Handle2 = Handle1;
while (itr.hasNext()) {
lastHandle = itr.next();
}
DriverManager.getCurrent().switchTo().window(Handle2.toString());
}
public static void switchToMainWindow() {
DriverManager.getCurrent().switchTo().window(Handle1.toString());
Following code might help you -
driver.findElement(By.xpath("//span[contains(text(),'CLOSE')]")).click();
or use JavascriptExecuter
in this way -
WebElement element = driver.findElement(By.xpath("//button[@class='close']"));
JavascriptExecutor js= (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
My guess would be that in order to close the dialog, you need to hit the "x". Im assuming this because you are waiting for the button element to become clickable, but it never does. So, id suggest making your locator more specific:
@FindBy(xpath = "//button[@class='close']/span")
WebElement closeButton;
Please let me know, if this works..or what happens if it does not.
From comment
thanks for the fast reply @cathal I get a timeout error that the element is not visible / locator able when the expected time elapses
Actually Your locator does not return unique result . There are multiple close button
element which have same class name close
.
Unfortunately you'r getting invisible dialog close button
, that's why you are in trouble.
You should try something as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
List<WebElement> elements = wait.until(ExpectedConditions
.presenceOfAllElementsLocatedBy(By.cssSelector(".close")));
for (WebElement element : elements) {
if (element.isDisplayed()) {
element.click();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.