How to open or handle the download page in multiple browsers using Selenium

Steps to handle download page

1.open browser

2. open website

3. download file

4. open new tab

5. load download page in the new tab

6. view the download file



Code is implemented for the IEDriver

IEDriver.java


import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class IEDriver {
	
	 static WebDriver driver;
    
	 @Test
	public static void open() throws InterruptedException{
		 
		System.setProperty("webdriver.edge.driver", "C:\\Users\\Prashant\\Desktop\\Automation\\edgedriver_win64\\msedgedriver.exe");
		driver = new EdgeDriver();
		driver.get("https://www.selenium.dev/downloads/");
	 
		driver.manage().window().maximize();
		((JavascriptExecutor) driver).executeScript("window.scrollBy(0,1150)");
		WebElement element = driver.findElement(By.xpath("//a[text()='64 bit Windows IE']"));
	
	    
		((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
		
	   driver.switchTo().newWindow(WindowType.TAB);
		 
	 //a[text()='64 bit Windows IE']
    	driver.get("edge://downloads/all");
    	WebDriverWait w = new WebDriverWait(driver, Duration.ofSeconds(30));
        w.until(ExpectedConditions
                .presenceOfElementLocated(By.xpath("//button[text()='IEDriverServer_x64_4.14.0.zip']")));
    	boolean isDownloadOrNot = driver.findElement(By.xpath("//button[text()='IEDriverServer_x64_4.14.0.zip']")).isDisplayed();
        if(isDownloadOrNot) {
        	System.out.println("File is downloaded sucessfully");
        }else {
        	System.out.print("File is not downloaded");
        }
	    driver.quit();

	}
}

Comments

Popular posts from this blog

Blocking google_vignette ads using selenium and java