FirefoxDriver driver = new FirefoxDriver(); driver.get("http://localhost:8080/page"); File file = null; try { file = new File(YourClass.class.getClassLoader().getResource("file.txt").toURI()); } catch (URISyntaxException e) { e.printStackTrace(); } Assert.assertTrue(file.exists()); WebElement browseButton = driver.findElement(By.id("myfile")); browseButton.sendKeys(file.getAbsolutePath());
FirefoxDriver driver = new FirefoxDriver(); driver.get("http://www.google.com/"); File scrFile = driver.getScreenshotAs(OutputType.FILE);
public class SimpleTest { public static void main(String[] args) { FirefoxDriver driver = new FirefoxDriver(); GoogleHomePage homePage = new GoogleHomePage(driver); driver.get("http://www.google.com"); homePage.doSearch("stack overflow"); System.out.println(driver.getTitle()); } }
FirefoxDriver wd=new FirefoxDriver(); wd.get("https://irctc.co.in/"); wd.manage().timeouts().implicitlyWait(5000,TimeUnit.SECONDS); WebElement wb=wd.findElement(By.linkText("Cabs")); wb.click(); //Now 2 Windows are open wd.manage().timeouts().implicitlyWait(5000,TimeUnit.SECONDS); //Wait for the complete page to load Set<String> sid=wd.getWindowHandles(); //getWindowHandles() method returns the ids of all active Windows and its return type will be a Collection Set. Iterator<String> it=sid.iterator(); //Using iterator we can fetch the values from Set. String parentId=it.next(); System.out.println(parentId); String childId=it.next(); System.out.println(childId); wd.switchTo().window(childId); //swtiching control to child Window
import org.openqa.selenium.firefox.FirefoxDriver; public class Test { public static void main(String[] args) { try{ FirefoxDriver driver = new FirefoxDriver(); driver.get("http:www.yahoo.com"); } catch(Exception e){ e.printStackTrace(); } } }
@Test public void testWithFirefox(FirefoxDriver firefox) { firefox.get("http://www.seleniumhq.org/"); assertTrue(firefox.getTitle().startsWith("Selenium")); }
FirefoxDriver Driver = new FirefoxDriver(); Driver.get("http://facebook.com/"); File ScrFile=Driver.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(ScrFile, new File("D://img.jpg"));
public void to(String url) { get(url); }
@Test public void testWithFirefox(FirefoxDriver firefox) { firefox.get("http://www.seleniumhq.org/"); assertTrue(firefox.getTitle().startsWith("Selenium")); }
public class Screenshot { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub FirefoxDriver driver = new FirefoxDriver(); driver.get("http://yahoo.com"); driver.manage().window().maximize(); File scrFile = (driver.getScreenshotAs(OutputType.FILE)); FileUtils.copyFile(scrFile, new File("d:\\Selenium\\screenshot2.png")); } }
public void to(URL url) { get(String.valueOf(url)); }
FirefoxDriver driver = new FirefoxDriver(); driver.get("ENTER YOU URL HERE"); // driver.findElement(By.id("group-container-1")).click(); This will work only if the element is not hidden. String jsExpression = "document.getElementById('group-container-1').click();"; ((JavascriptExecutor) driver).executeScript(jsExpression);
FirefoxDriver driver = new FirefoxDriver(); List<String> urls = new ArrayList<>(); // load the urls List for (String url : urls) { driver.get(url); // do stuff to page }
public class FirefoxTest { @Test public void FirefoxTest_Test1() { System.setProperty("webdriver.gecko.driver","D:\\Firefox\\geckodriver.exe"); FirefoxDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); } }
FirefoxDriver driver = new FirefoxDriver(); driver.get("https://www.google.com"); List<WebElement> links = driver.findElements(By.cssSelector("#gbw a.gb_P")); for (WebElement link : links) { System.out.println(link.getText().trim()); }
static WebElement searchbox; public static void main(String[] args) { FirefoxDriver driver = new FirefoxDriver(); driver.get("http://www.amazon.in"); searchbox = driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']")); }
static WebElement searchbox; public static void main(String[] args) { FirefoxDriver driver = new FirefoxDriver(); driver.get("http://www.amazon.in"); searchbox = driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']")); }
public class demo { public static void main(String[] args) throws IOException, InterruptedException { FirefoxDriver driver = new FirefoxDriver(); //OPEN SPECIFIC URL IN BROWSER driver.get("http://www.toolsqa.com/automation-practice-form/"); //SELECT SPECIFIC VALUE FROM DROPDOWN Select sel = new Select(driver.findElement(By.id("continents"))); sel.selectByVisibleText("Australia"); } }
By hiddenLocator = By.id("csi"); FirefoxDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("http://www.google.com"); WebElement hiddenEle = driver.findElement(hiddenLocator); WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.presenceOfElementLocated(hiddenLocator)); System.out.println("done");