Showing posts with label Handling alerts in selenium. Show all posts
Showing posts with label Handling alerts in selenium. Show all posts

Difference Between Implicit Wait and Explicit Wait


Implicit Wait – 

An implicit wait is to tell WebDriver to stop the DOM for a certain amount of time. The default setting is 0. 

Syntax – driver.manage().timeouts().Implicitly Wait(10, TimeUnit.SECONDS); 

Explicit Wait - 

Handling Alerts with Selenium

 

// How to handle alerts in Selenium

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class HandlingAlerts {

	public static void main(String[] args) throws InterruptedException {
		WebDriver driver = new FirefoxDriver();
		String Url = "http://sislands.com/coin70/week1/dialogbox.htm";
		driver.get(Url);
		WebElement alert = driver.findElement(By.xpath("html/body/div[1]/center/table/tbody/tr/td/form[1]/p/input"));
		alert.click();
		Alert popup = driver.switchTo().alert();
		System.out.println(popup.getText());
popup.accept();
		Thread.sleep(3000);
		
		driver.close();

		
		
	}
}