List of usage examples for org.openqa.selenium WebDriver switchTo
TargetLocator switchTo();
From source file:fll.web.IntegrationTestUtils.java
License:Open Source License
/** * Initialize the database using the given challenge descriptor. * /*w ww . java2 s . c om*/ * @param driver the test controller * @param challengeFile a file to read the challenge description from. This * file will not be deleted. * @throws InterruptedException * @throws IOException */ public static void initializeDatabase(final WebDriver driver, final Path challengeFile) throws InterruptedException { driver.get(TestUtils.URL_ROOT + "setup/"); Thread.sleep(WAIT_FOR_PAGE_LOAD_MS); if (isElementPresent(driver, By.name("submit_login"))) { login(driver); driver.get(TestUtils.URL_ROOT + "setup/"); Thread.sleep(WAIT_FOR_PAGE_LOAD_MS); } final WebElement fileEle = driver.findElement(By.name("xmldocument")); fileEle.sendKeys(challengeFile.toAbsolutePath().toString()); final WebElement reinitDB = driver.findElement(By.name("reinitializeDatabase")); reinitDB.click(); Thread.sleep(WAIT_FOR_PAGE_LOAD_MS); try { final Alert confirmCreateDB = driver.switchTo().alert(); LOGGER.info("Confirmation text: " + confirmCreateDB.getText()); confirmCreateDB.accept(); } catch (final NoAlertPresentException e) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("No alert found, assuming the database was empty and didn't need an alert."); } } Thread.sleep(2 * WAIT_FOR_PAGE_LOAD_MS); driver.findElement(By.id("success")); // setup user final WebElement userElement = driver.findElement(By.name("user")); userElement.sendKeys(TEST_USERNAME); final WebElement passElement = driver.findElement(By.name("pass")); passElement.sendKeys(TEST_PASSWORD); final WebElement passCheckElement = driver.findElement(By.name("pass_check")); passCheckElement.sendKeys(TEST_PASSWORD); final WebElement submitElement = driver.findElement(By.name("submit_create_user")); submitElement.click(); Thread.sleep(2 * WAIT_FOR_PAGE_LOAD_MS); driver.findElement(By.id("success-create-user")); login(driver); }
From source file:fll.web.IntegrationTestUtils.java
License:Open Source License
/** * Initialize a database from a zip file. * //w w w. java 2s . com * @param selenium the test controller * @param inputStream input stream that has database to load in it, this input * stream is closed by this method upon successful completion * @throws IOException * @throws InterruptedException */ public static void initializeDatabaseFromDump(final WebDriver selenium, final InputStream inputStream) throws IOException, InterruptedException { Assert.assertNotNull(inputStream); final File dumpFile = IntegrationTestUtils.storeInputStreamToFile(inputStream); try { selenium.get(TestUtils.URL_ROOT + "setup/"); if (isElementPresent(selenium, By.name("submit_login"))) { login(selenium); selenium.get(TestUtils.URL_ROOT + "setup/"); } final WebElement dbEle = selenium.findElement(By.name("dbdump")); dbEle.sendKeys(dumpFile.getAbsolutePath()); final WebElement createEle = selenium.findElement(By.name("createdb")); createEle.click(); try { final Alert confirmCreateDB = selenium.switchTo().alert(); LOGGER.info("Confirmation text: " + confirmCreateDB.getText()); confirmCreateDB.accept(); } catch (final NoAlertPresentException e) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("No alert found, assuming the database was empty and didn't need an alert."); } } selenium.findElement(By.id("success")); // setup user final WebElement userElement = selenium.findElement(By.name("user")); userElement.sendKeys(TEST_USERNAME); final WebElement passElement = selenium.findElement(By.name("pass")); passElement.sendKeys(TEST_PASSWORD); final WebElement passCheckElement = selenium.findElement(By.name("pass_check")); passCheckElement.sendKeys(TEST_PASSWORD); final WebElement submitElement = selenium.findElement(By.name("submit_create_user")); submitElement.click(); selenium.findElement(By.id("success-create-user")); login(selenium); } finally { if (!dumpFile.delete()) { dumpFile.deleteOnExit(); } } login(selenium); }
From source file:fll.web.playoff.TestAJAXBrackets.java
License:Open Source License
private void enterScore(final WebDriver webDriver, final String team, final int score) { final Select teamSelect = new Select(webDriver.findElement(By.id("select-teamnumber"))); teamSelect.selectByValue(team);//from ww w . j a v a2 s . c om webDriver.findElement(By.id("enter_submit")).click(); for (int i = 0; i < score; i++) { webDriver.findElement(By.id("inc_score_1")).click(); } webDriver.findElement(By.id("submit")).click(); Alert confirmScoreChange = null; final int maxAttempts = 5; int attempt = 0; while (null == confirmScoreChange && attempt <= maxAttempts) { try { confirmScoreChange = webDriver.switchTo().alert(); LOGGER.info("Confirmation text: " + confirmScoreChange.getText()); confirmScoreChange.accept(); } catch (final NoAlertPresentException ex) { ++attempt; confirmScoreChange = null; if (attempt >= maxAttempts) { throw ex; } else { LOGGER.warn("Trouble finding alert, trying again", ex); } } } }
From source file:GlennsPack.GlennWebAPI.Example.java
License:Open Source License
public void gojbSpam() { System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().setSize(new Dimension(2000, 800)); driver.get("http://gojb.ml/chat"); try {/* w ww.j a va 2 s .c o m*/ Thread.sleep(500); } catch (InterruptedException e1) { // FIXME Auto-generated catch block e1.printStackTrace(); } driver.findElement(By.xpath("//*[@id=\"menu\"]/div/ul/li[1]/div/p")).click(); ; driver.findElement(By.id("knapp")).click(); try { Thread.sleep(2000); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } driver.switchTo().alert().sendKeys("GoJbBot"); driver.switchTo().alert().accept(); driver.findElement(By.id("knapp2")).click(); for (int i = 0; i < 1000; i++) { str = ""; for (int i1 = 0; i1 < 10; i1++) { str = str + abc.charAt(rand.nextInt(abc.length())); } driver.findElement(By.id("chat")).sendKeys(str, Keys.ENTER); } }
From source file:GlennsPack.GlennWebAPI.findTextInPage.java
License:Open Source License
public findTextInPage(ArrayList<String> lookFor) { System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().setSize(new Dimension(2000, 800)); driver.get("http://gojb.ml/chat"); try {// ww w.j ava2 s . co m Thread.sleep(500); } catch (InterruptedException e1) { // FIXME Auto-generated catch block e1.printStackTrace(); } driver.findElement(By.xpath("//*[@id=\"menu\"]/header/div[1]")).click(); driver.findElement(By.id("knapp")).click(); try { Thread.sleep(2000); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } driver.switchTo().alert().sendKeys("GoJbBot"); driver.switchTo().alert().accept(); driver.findElement(By.id("knapp2")).click(); while (found != true) { try { for (int index = 0; index < lookFor.size(); index++) { List<WebElement> element = driver .findElements(By.xpath("//*[contains(translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ'," + "'abcdefghijklmnopqrstuvwxyz'),\"" + lookFor.get(index).toLowerCase() + "\")]")); for (int i = 0; i < element.size(); i++) { if (!mathingsFound.contains(element.get(i).getText())) { mathingsFound.add(element.get(i).getText()); System.out.println("FOUND!"); Found(lookFor.get(index).toLowerCase(), element.get(i).getText(), driver); } else { missmatch++; if ((missmatch * lookFor.size()) == element.size()) { System.out.println("OR ELSE"); throw new Exception(); } } } } } catch (Exception e2) { } try { Thread.sleep(1000); } catch (InterruptedException e) { // FIXME Auto-generated catch block e.printStackTrace(); } } }
From source file:gov.nih.nci.firebird.commons.selenium2.util.AlertUtils.java
License:Open Source License
public static void clickOk(WebDriver driver) { driver.switchTo().alert().accept(); }
From source file:gov.nih.nci.firebird.commons.selenium2.util.AlertUtils.java
License:Open Source License
public static String getMessage(WebDriver driver) { return driver.switchTo().alert().getText(); }
From source file:gov.nih.nci.firebird.commons.selenium2.util.AlertUtils.java
License:Open Source License
public static void clickCancel(WebDriver driver) { driver.switchTo().alert().dismiss(); }
From source file:io.github.seleniumquery.by.firstgen.css.pseudoclasses.FocusPseudoClass.java
License:Apache License
@Override public boolean isPseudoClass(WebDriver driver, WebElement element, PseudoClassSelector pseudoClassSelector) { WebElement currentlyActiveElement = driver.switchTo().activeElement(); return element.equals(currentlyActiveElement); }
From source file:io.selendroid.client.waiter.WaitingConditions.java
License:Apache License
public static Callable<Alert> alertToBePresent(final WebDriver driver) { return new Callable<Alert>() { public Alert call() throws Exception { try { return driver.switchTo().alert(); } catch (NoAlertPresentException e) { return null; }/*from ww w . j a va 2 s . c o m*/ } }; }