AcceptAlert() is not working. it throws timeout exception
public void AcceptAlert(){
try{
WebDriverWait wait = new WebDriverWait(driver, 29);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
System.out.println("alert was present and accepted");
}
catch(Exception e) {
System.out.println("alert was not present");
System.out.print(e);
}
}
Error:
org.openqa.selenium.TimeoutException: Timed out after 29 seconds waiting for alert to be present
Instructor
Ashish Thakur Replied on 28/05/2020
On which URL are you trying this code
Instructor
Ashish Thakur Replied on 29/05/2020
I am not getting any alert on this URL
Delete Popup is appeared when i try to delete a Lead
Instructor
Ashish Thakur Replied on 01/06/2020
Ok.. please use explicit wait and wait till the alert is present
I have alredy used explict wait and wait till alert is present. Its not working .
it throws timeout exception
publicvoidAcceptAlert(){
try{
WebDriverWaitwait=newWebDriverWait(driver,29);
wait.until(ExpectedConditions.alertIsPresent());
Alertalert=driver.switchTo().alert();
alert.accept();
System.out.println("alert was present and accepted");
}
catch(Exceptione){
System.out.println("alert was not present");
System.out.print(e);
}
}
Instructor
Ashish Thakur Replied on 03/06/2020
Use simple pause - life thread.sleep
Also send your project in attachment
LeadTest.Java
Ingnore above file and consider attched project