My Html
<div id="981bdff3-90a1-4966-ada9-6550b5a963bc" class="modal bootstrap-dialog type-primary fade size-normal in" aria-hidden="false" role="dialog" aria- labelledby="981bdff3-90a1-4966-ada9-6550b5a963bc_title" tabindex="-1" style="display: block; padding-right: 17px;">
<div class="modal-backdrop fade in" style="height: 351px;"></div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div class="bootstrap-dialog-header">
<div class="bootstrap-dialog-close-button" style="display: none;">
<button class="close">×</button>
</div>
<div id="981bdff3-90a1-4966-ada9-6550b5a963bc_title" class="bootstrap-dialog-title">Are you sure?</div>
</div>
</div>
<div class="modal-body">
<div class="bootstrap-dialog-body">
<div class="bootstrap-dialog-message">You will lose all data !</div>
</div>
</div>
<div class="modal-footer" style="display: block;">
<div class="bootstrap-dialog-footer">
<div class="bootstrap-dialog-footer-buttons">
<button id="1b0400a9-c69b-429f-9bdd-11112b7cb3a4" class="btn btn-default">Cancel</button>
<button id="3e4fec25-9538-4351-92b1-c7f9f8ce9574" class="btn btn-primary">OK</button>
</div>
</div>
</div>
</div>
</div>
My Java
package Modules;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import Config.config;
public class AddCollectionPoint_Email {
@Test
@Parameters({"DATAPROVIDER"})
public void Addcollection(String DataProvider)
{
config.driver.findElement(By.id("collectionPointsMenu")).click();
config.driver.findElement(By.xpath("//a[@href='addCollectionPoint']")).click();
config.driver.findElement(By.xpath("//a[@data-ng-click='resetEmailCollectionTab()']")).click();
config.driver.findElement(By.xpath("//a[@data-ng-click='resetFtpCollectionTab()']")).click();
**config.driver.findElement(By.xpath("//a[@data-ng-click='resetEmailCollectionTab()']")).click();**
WebElement element = config.driver.findElement(By.xpath("//div[@class='modal-content']")).findElement(By.xpath("//div[@class='modal-footer']"))
.findElement(By.xpath("//div[@class='bootstrap-dialog-footer-buttons']")).findElement(By.xpath("//button[@class='btn btn-primary']"));
JavascriptExecutor executor = (JavascriptExecutor)config.driver;
executor.executeScript("arguments[0].click();", element);
config.driver.findElement(By.xpath("//input[@name='selectedDataProvider']")).sendKeys(DataProvider);
}
}
I am not able to click on "OK" Button I a getting exception element not visible. Then I had implemented Webdriver wait but it also doesnt work and i got timeoutexception. Please help me regarding this.My code is working fine upto the double asteric mark line.
When a popup happens, I believe it's registered as a new window within the driver. You may need to switch to the new window in order to resolve the elements on that page.
public class AddCollectionPoint_Email {
@Test
@Parameters({"DATAPROVIDER"})
public void Addcollection(String DataProvider)
{
config.driver.findElement(By.id("collectionPointsMenu")).click();
config.driver.findElement(By.xpath("//a[@href='addCollectionPoint']")).click();
config.driver.findElement(By.xpath("//a[@data-ng-click='resetEmailCollectionTab()']")).click();
config.driver.findElement(By.xpath("//a[@data-ng-click='resetFtpCollectionTab()']")).click();
//Capture the current Working Window handle
String currentWindowHandle = config.driver.getWindowHandle();
//Performing this interaction causes the confirmation dialog to open.
config.driver.findElement(By.xpath("//a[@data-ng-click='resetEmailCollectionTab()']")).click();**
//At this point I expect there to be 2 window handles. My original and the new one opened by the previous invocation.
List<String> allHandles = config.driver.getWindowHandles();
//assert size maybe?
allHandles.remove(currentWindowHandle);
String dialogHandle = allHandles.get(0);
try {
//Transfer focus to the dialog!
config.driver.switchTo().window(dialogHandle);
//Now we're on the dialog, find the button and click it.
WebElement element = config.driver.findElement(By.xpath("//div[@class='modal-content']")).findElement(By.xpath("//div[@class='modal-footer']"))
.findElement(By.xpath("//div[@class='bootstrap-dialog-footer-buttons']")).findElement(By.xpath("//button[@class='btn btn-primary']"));
} finally {
//All actions on the dialog are completed, switch back to the main window to continue process.
config.driver.switchTo().window(currentWindowHandle);
}
//I'm assuming this happens in the original window. Move into the try block if it happens in the dialog.
JavascriptExecutor executor = (JavascriptExecutor)config.driver;
executor.executeScript("arguments[0].click();", element);
config.driver.findElement(By.xpath("//input[@name='selectedDataProvider']")).sendKeys(DataProvider);
}
}
i do not understand if you tried the click on the WebElement method element.click();
Can you specify your WebDriver implementation and post the logs.
I guess it's that click opens the popup, config.driver.findElement(By.xpath("//a[@data-ng-click='resetEmailCollectionTab()']")).click();
can you check if this boolean value is true
boolean isDisplayed = config.driver.findElement(By.xpath("//div[@class='modal-content']")).findElement(By.xpath("//div[@class='modal-footer']"))
.findElement(By.xpath("//div[@class='bootstrap-dialog-footer-buttons']")).findElement(By.xpath("//button[@class='btn btn-primary']")).isDisplayed();
Try this:
WebDriverWait wait = new WebDriverWait(config.driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='modal-content']"))));
WebElement element = config.driver.findElement(By.xpath("//div[@class='modal-content']")).findElement(By.xpath("//div[@class='modal-footer']")) .findElement(By.xpath("//div[@class='bootstrap-dialog-footer-buttons']")).findElement(By.xpath("//button[@class='btn btn-primary']"));
JavascriptExecutor executor = (JavascriptExecutor)config.driver;
executor.executeScript("arguments[0].click();", element);
config.driver.findElement(By.xpath("//input[@name='selectedDataProvider']")).sendKeys(DataProvider);
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.