List of usage examples for org.openqa.selenium WebDriver get
void get(String url);
From source file:com.mycompany.seleniumtest.Selenium2Example.java
public static void main(String[] args) { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver"); System.setProperty("webdriver.safari.driver", "/usr/bin/safaridriver"); //WebDriver driver = new ChromeDriver(); WebDriver driver = new ChromeDriver(); // And now use this to visit the cars program driver.get("http://localhost:3000/"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); //verify the page is loaded, wait 10 seconds if it doesn't try {//from ww w. ja va2s . c om driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); System.out.println("Page loaded!"); } catch (Exception e) { System.err.println(e.getMessage()); System.err.println(e.getStackTrace()); } int rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); if (rowCount == 5) { System.out.println(rowCount + " is the row count!"); } else { System.out.println("rowcount should be different!"); } // Find the filter input element by its name WebElement searchFilter = driver.findElement(By.id("filter")); // Enter 2002 to search for searchFilter.sendKeys("2002"); //check if there are two rows left rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); System.out.println("Row count after filter is: " + rowCount); searchFilter.clear(); searchFilter.sendKeys(""); rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); System.out.println("Row count after filter is: " + rowCount); //Close the browser driver.quit(); }
From source file:com.mycompany.seliniumtest.Selenium2Example.java
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "/usr/local/Cellar/geckodriver/geckodriver"); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. //WebDriver driver = new FirefoxDriver(); //WebDriver driver = new ChromeDriver(); WebDriver driver = new FirefoxDriver(); //WebDriver driver = new HtmlUnitDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();/*from w ww.java 2s . c o m*/ // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.mycompany.webcalculator.OperationsSeleniumTest.java
public void login(WebDriver driver, String siteURL, String username, String password) { driver.get(siteURL); System.out.println(siteURL);/*from w ww.j a v a 2 s .c o m*/ //wait.until(ExpectedConditions.presenceOfElementLocated(By.id("userid"))); System.out.println("Loading URL.."); //extent.log(LogStatus.INFO, "Images", "Image:", imageMap + imageName); // takeScreenShot(caseName); screenshot.Capture(driver, imageLocation); driver.findElement(By.name("em")).clear(); System.out.println("Waiting for User Id..."); driver.findElement(By.name("em")).sendKeys(username); System.out.println("User Id " + username + " entered."); screenshot.Capture(driver, imageLocation); //takeScreenShot("test 2"); driver.findElement(By.name("pw")).clear(); System.out.println("Waiting for Password..."); driver.findElement(By.name("pw")).sendKeys(password); System.out.println("Password ******* entered."); screenshot.Capture(driver, imageLocation); //driver.findElement(By.xpath("//button[text()='Submit']")).click(); driver.findElement(By.name("Login")).click(); System.out.println("Logging in..."); screenshot.Capture(driver, imageLocation); assertTrue(driver.getPageSource().contains("Invalid login. Please try again")); }
From source file:com.nat.test.utils.PageNavigator.java
/** * Navigate to the page with the login form. Need to sign out before * calling. Returns null if it's not possible to get the Login page * * @param driver// ww w. ja v a 2 s.co m * The driver that will be used for navigation * @return An instance of {@link LoginPage} class or null if it's not * possible to get the Login page */ public LoginPage getLoginPage(WebDriver driver) { loginPage = null; driver.get(TestData.BASE_URL); try { startPage = PageFactory.initElements(driver, StartPage.class); loginPage = startPage.navigateToLogin(); } catch (Exception e) { e.printStackTrace(); System.out.println("Can't get the Login page"); } return loginPage; }
From source file:com.nat.test.utils.PageNavigator.java
/** * Method to get the page with just created repository. Need to sign out * before calling. Returns null if it's not possible to get the Repository * page/*from w ww.j ava 2s . c om*/ * * @param driver * The driver that will be used for navigation * @param repDescription * Repository description * @param addReadme * If true, initialize repository with a README * @param gitignore * Select gitignore from the dropdown * @param license * Select license type from the dropdown * * @return An instance of {@link RepositoryPage} class or null if it's not * possible to login or get the Repository page */ public RepositoryPage getNewRepositoryPage(WebDriver driver, String repDescription, boolean addReadme, String gitignore, String license) { repositoryPage = null; try { driver.get(TestData.BASE_URL); homePage = login(driver); createRepositoryPage = homePage.createNewRepository(); String currentRepName = getUniqueRepName(); repositoryPage = createRepositoryPage.createRepository(currentRepName, repDescription, addReadme, gitignore, license); } catch (Exception e) { e.printStackTrace(); System.out.println("Can't get RepositoryPage"); } return repositoryPage; }
From source file:com.nat.test.utils.PageNavigator.java
/** * Method to log out and get Start page from any page. Ren null if it's not * possible to log out or get the Start page * * @param driver/* ww w. j ava2 s . c om*/ * The driver that will be used for navigation * @param page * Current page * @return An instance of {@link StartPage} class or null if it's not * possible to log out or get the Start page */ public StartPage logout(WebDriver driver, Page page) { try { page.logout(); driver.get(TestData.BASE_URL); startPage = PageFactory.initElements(driver, StartPage.class); return startPage; } catch (Exception e) { e.printStackTrace(); System.out.println("Can't get Start page"); return null; } }
From source file:com.openones.auto.selen.Sample01.java
License:Apache License
public static void main(String[] args) { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new FirefoxDriver(); //WebDriver driver = new InternetExplorerDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();/*from w w w. j a va 2s.c om*/ // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.oracle.pgbu.p6web.helper.DataHelper.java
public void approveTimesheet(int tsPeriodID, int rsrcID, WebDriver m_driver) throws InterruptedException { TSUtil.approveTimesheet(tsPeriodID, rsrcID); Thread.sleep(1000);/*from w w w. j a v a 2s . co m*/ m_driver.get(appProperties.getUrl()); }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method shall wait for the title and return it. * /* w ww . java2s . co m*/ * @param driver * @param url - URL to access */ public void Get(final WebDriver driver, final String url) { this.log.debug("Get(Main)::Enter"); driver.get(url); String complete = "complete"; String state = ((JavascriptExecutor) driver).executeScript("return document.readyState").toString(); this.log.debug("Page state: " + state); for (int i = 0; i < 20; i++) { if (!state.equalsIgnoreCase(complete)) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } state = ((JavascriptExecutor) driver).executeScript("return document.readyState").toString(); this.log.debug("Page state: " + state); } else { break; } } this.log.debug("Get(Main)::Exit"); }
From source file:com.perceptron.findjesus.Util.java
License:MIT License
public static void navigateToWikipedia(WebDriver browser) { browser.get("http://en.wikipedia.org/wiki/Main_Page"); }