Skip to main content

Posts

Showing posts with the label Selenium

How to Handle Alerts and Frames in WebDriver

We come across mainly two types of alerts in web applications : window based alerts and web based alerts. Window based alerts cannot be handled by webdriver and we have to take the help of external tools for handling them. Here we discuss on how to handle alerts(web based) and frames using Selenium WebDriver. Summary Handle Alerts Wait For Alert Get Alert Text Accept or Dismiss Alert Type on Alert Authenticate using Alert Handle Frames Identifying Frames Switch to Frame Switch to Main Content Handle Alerts We use driver.switchTo().alert() method to handle alerts in webdriver. It returns an Alert object using which we can the alert can be processed. 1 Alert alert = driver.switchTo().alert(); Wait For Alert Most often, we may have to wait for the alert to come up. Instead of using Thread.sleep(), we can use WebDriverWait as shown below. 1 2 3 4 WebDriverWait wait = new WebDriverWait(driver, 2 ); wait.until(ExpectedConditions.alertIsP