Raj
Raj

Reputation: 221

How to show the alert in 10 seconds in selenium

My Requirement: I want to show the alert on my page some seconds to read.If any function is to help in Selenium Web-driver.

I am a new bee to this automation fields I have studied about the explicit wait so I use the explicit wait as below but It doesn't show the alert in my required time.

Below is my code,

WebDriverWait wait = new WebDriverWait (driver, 30);
JavaScriptExecutor js = (JavascriptExecutor)driver;
wait.until(ExpectedConditions.elementToBeClickable(By.id("username"))).clear();
wait.until(ExpectedConditions.elementToBeClickable(By.id("username"))).sendKeys(username);          
wait.until(ExpectedConditions.elementToBeClickable(By.id("password"))).clear();
wait.until(ExpectedConditions.elementToBeClickable(By.id("password"))).sendKeys(password);      
wait.until(ExpectedConditions.elementToBeClickable(By.id("Login"))).click();   
String det1 = driver.findElement(By.id(elem id)).getText();
String det2 = driver.findElement(By.id(elem id)).getText();
String det3 = driver.findElement(By.id(elem id)).getText();
String det4 = driver.findElement(By.id(elem id)).getText();    
js.executeScript("window.alert('Values are..'"+det1+" "+det2+" "+det3+" "+det4"+'')");
driver.switchTo().alert().accept();

the above code is good to show my det values but it shows the alert in very little time and closes the alert. So How I make the alert to show my details in some seconds before it's closed.

Upvotes: 0

Views: 1624

Answers (1)

JeffC
JeffC

Reputation: 25611

Don't use an alert to display information. Use a framework like TestNG or JUnit to log pass/fails and then look at the logs. You want automation to go as fast as it can. It defeats a lot of the purpose of automation when you require manual intervention or someone watching the script run to see if it passed or not.

Upvotes: 6

Related Questions