
- Legal services
- Legal advice
- Lawyer referral services
- Legal representation
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; public class Training { static WebDriver driver; public static void main(String[] args) throws InterruptedException { FirefoxProfile firefoxprofile = new FirefoxProfile(); firefoxprofile.setPreference("browser.download.dir", "D:\\download"); firefoxprofile.setPreference("browser.download.folderList", 2); firefoxprofile .setPreference( "browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;" + "application/pdf;" + "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" + "text/plain;" + "text/csv"); firefoxprofile.setPreference( "browser.download.manager.showWhenStarting", false); firefoxprofile.setPreference("pdfjs.disabled", true); driver = new FirefoxDriver(firefoxprofile); driver.get("reditblog.blogspot.in/2014/12/how-to-download-file-using-selenium.html"); driver.findElement(By.name("text")).click(); Thread.sleep(5000); driver.findElement(By.name("pdf")).click(); Thread.sleep(5000); driver.findElement(By.name("CSV")).click(); Thread.sleep(5000); driver.findElement(By.name("Excel File")).click(); Thread.sleep(5000); driver.findElement(By.name("Doc")).click(); Thread.sleep(5000); driver.quit(); } }
import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Training { static WebDriver driver; public static void main(String[] args) throws InterruptedException { driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http:// www.google .com/"); driver.findElement(By.name("q")).sendKeys("http://reditblog.blogspot.in"); Thread.sleep(5000); WebElement element1 = driver.findElement(By.name("btnK")); JavascriptExecutor executor1 = (JavascriptExecutor) driver; executor1.executeScript("arguments[0].click();", element1); Thread.sleep(5000); WebElement element2 = driver.findElement(By.linkText("Reditblog")); JavascriptExecutor executor2 = (JavascriptExecutor) driver; executor2.executeScript("arguments[0].click();", element2); Thread.sleep(5000); driver.quit(); } }
import java.util.concurrent.TimeUnit; 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 Training { static WebDriver driver; public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.navigate().to( "http://www. w3schools. com/js/tryit. asp?filename=tryjs_alert"); driver.switchTo().frame(0); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement element = driver.findElement(By.tagName("button")); element.click(); Alert alert = driver.switchTo().alert(); System.out.println(alert.getText()); Thread.sleep(5000); alert.accept(); } }
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; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Training { static WebDriver driver; public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.navigate().to( "http:// www. w3schools. com/js/tryit. asp?filename=tryjs_alert"); driver.switchTo().frame(0); WebElement element1 = (new WebDriverWait(driver, 10)) .until(ExpectedConditions.elementToBeClickable(By .tagName("button"))); WebElement element = driver.findElement(By.tagName("button")); element.click(); Alert alert = driver.switchTo().alert(); System.out.println(alert.getText()); Thread.sleep(5000); alert.accept(); } }
import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Training { static WebDriver driver; public static void main(String[] args) { driver = new FirefoxDriver(); driver.get("http://www.google.com"); driver.manage().window().maximize(); try { driver.findElement( By.xpath("//*[@id='Blog1]")) .sendKeys("test"); } catch (Exception e) { System.out.println("Please look at D:\\screenshot.png for screenshot!"); try { getscreenshot(); } catch (Exception e1) { System.out.println(e1); } } } public static void getscreenshot() throws Exception { File scrFile = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File("D:\\screenshot.png")); } }
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; public class Training { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("https:// login.yahoo. com/?.src=ym&.intl=us&.lang=en-US&.done=https%3a// mail.yahoo. com"); driver.manage().window().maximize(); driver.findElement(By.id("login-username")).sendKeys("some text"); driver.findElement(By.id("login-passwd")).sendKeys("some password"); } }
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; public class Training { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http: //jqueryui. com/droppable/"); driver.manage().window().maximize(); driver.switchTo().frame(0); driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS); WebElement dragElement = driver.findElement(By.id("draggable")); WebElement dropElement = driver.findElement(By.id("droppable")); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(dragElement) .moveToElement(dropElement).release(dropElement).build(); dragAndDrop.perform(); } }
import java.util.Set; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Training { public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.navigate().to("http:// www.flipkart. com/"); Cookie name = new Cookie("mycookie", "12345"); driver.manage().addCookie(name); // Let's get the cookie's value Set<cookie> cookies = driver.manage().getCookies(); for (Cookie getcookies : cookies) { System.out.println(getcookies); } /* * You can delete cookies in 3 ways 1. By name * driver.manage().deleteCookieNamed("CookieName"); * * 2. By Cookie driver.manage().deleteCookie(getcookies); * * 3. All Cookies driver.manage().deleteAllCookies(); */ driver.manage().deleteAllCookies(); } }