Created
March 26, 2021 11:14
-
-
Save Jaimin180296/ee22f156609c43c429fd845d6cc04876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.JavascriptExecutor; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import java.net.URL; | |
public class FileDownload { | |
public static final String USERNAME = "<username>"; | |
public static final String AUTOMATE_KEY = "<accesskey>"; | |
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub"; | |
public static void main(String[] args) throws Exception { | |
DesiredCapabilities caps = new DesiredCapabilities(); | |
caps.setCapability("os", "Windows"); | |
caps.setCapability("os_version", "10"); | |
caps.setCapability("browser", "IE"); | |
caps.setCapability("browser_version", "11.0"); | |
caps.setCapability("name", "Bstack-[Java] Sample file download"); | |
WebDriver driver = new RemoteWebDriver(new URL(URL), | |
caps); | |
JavascriptExecutor jse = (JavascriptExecutor) driver; | |
driver.get("https://unsplash.com/photos/s9CC2SKySJM"); | |
Thread.sleep(2000); | |
WebElement Element = driver.findElement(By.xpath("//span[.='Download free']")); | |
// Click on the element to download the file | |
Element.click(); | |
Thread.sleep(2000); | |
jse.executeScript("browserstack_executor: {\"action\": \"saveFile\"}"); | |
Thread.sleep(2000); | |
driver.quit(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment