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
@Test | |
public void navigationHistory() { | |
driver.navigate().to("https://www.codeproject.com/Articles/1078541/Advanced-WebDriver-Tips-and-Tricks-Part"); | |
driver.navigate().to("http://www.codeproject.com/Articles/1017816/Speed-up-Selenium-Tests-through-RAM-Facts-and-Myth"); | |
driver.navigate().back(); | |
Assert.assertEquals("10 Advanced WebDriver Tips and Tricks - Part 1 - CodeProject", driver.getTitle()); | |
driver.navigate().refresh(); |
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
@Test | |
public void movingBetweenTabs() { | |
driver.navigate().to("https://www.automatetheplanet.com/"); | |
var firstLink = driver.findElement(By.xpath("//*[@id='menu-item-11362']/a")); | |
var secondLink = driver.findElement(By.xpath("//*[@id='menu-item-6']/a")); | |
String selectLinkOpenninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN); | |
firstLink.sendKeys(selectLinkOpenninNewTab); | |
secondLink.sendKeys(selectLinkOpenninNewTab); | |
Set<String> windows = driver.getWindowHandles(); | |
String firstTab = (String)windows.toArray()[1]; |
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
@Test | |
public void handleJavaScripPopUps() { | |
driver.navigate().to("http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm"); | |
driver.switchTo().frame("iframeResult"); | |
var button = driver.findElement(By.xpath("/html/body/button")); | |
button.click(); | |
Alert alert = driver.switchTo().alert(); | |
if (alert.getText().equals("Press a button!")) { | |
alert.accept(); |
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
@Test | |
public void fileUpload() throws IOException { | |
driver.navigate().to( | |
"https://demos.telerik.com/aspnet-ajax/ajaxpanel/application-scenarios/file-upload/defaultcs.aspx"); | |
var element = driver.findElement(By.id("ctl00_ContentPlaceholder1_RadUpload1file0")); | |
String filePath = Paths.get(getProperty("java.io.tmpdir"), "debugWebDriver.xml").toString(); | |
File destFile = new File(filePath); | |
destFile.createNewFile(); |
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
@Test | |
public void dragAndDrop() { | |
driver.navigate().to("http://loopj.com/jquery-simple-slider/"); | |
var element = driver.findElement(By.xpath("//*[@id='project']/p[1]/div/div[2]")); | |
Actions action = new Actions(driver); | |
action.dragAndDropBy(element, 30, 0).build().perform(); | |
} |
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
driver.manage().window().maximize(); |
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
@Test | |
public void manageCookies() { | |
driver.navigate().to("http://automatetheplanet.com"); | |
// get all cookies | |
var cookies = driver.manage().getCookies(); | |
for (Cookie cookie:cookies) { | |
System.out.println(cookie.getName()); | |
} |
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
ChromeOptions chromeOptions = new ChromeOptions(); | |
chromeOptions.addExtensions(new File("local/path/to/extension.crx")); | |
driver = new ChromeDriver(chromeOptions); |
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
ProfilesIni profile = new ProfilesIni(); | |
FirefoxProfile firefoxProfile = profile.getProfile("xyzProfile"); | |
String downloadFilepath = "c:\\temp"; | |
firefoxProfile.setPreference("browser.download.folderList", 2); | |
firefoxProfile.setPreference("browser.download.dir", downloadFilepath); | |
firefoxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false); | |
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", | |
"application/msword, application/binary, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")); | |
FirefoxOptions firefoxOptions = new FirefoxOptions(); |
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
@Test | |
public void checkIfElementIsVisible() { | |
driver.navigate().to("http://automatetheplanet.com"); | |
var element = driver.findElement(By.xpath("/html/body/div[1]/header/div/div[2]/div/div[2]/nav"); | |
Assert.assertTrue(element).isDisplayed()); | |
} |