Example usage for org.openqa.selenium WebDriver manage

List of usage examples for org.openqa.selenium WebDriver manage

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver manage.

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:selenium.MarcosTolentino.java

/**
 * @param args the command line arguments
 *//*from w  w w .j  a v a2 s .co m*/
public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.minha.unidavi.edu.br");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.findElement(By.id("UWS_FRM_USR_NOME")).clear();
    driver.findElement(By.id("UWS_FRM_USR_NOME")).sendKeys("32434");
    driver.findElement(By.name("UWS_FRM_USR_SENHA")).clear();
    driver.findElement(By.name("UWS_FRM_USR_SENHA")).sendKeys("537537");
    driver.findElement(By.name("acao")).click();
    driver.findElement(By.linkText("Sala Virtual")).click();
    driver.findElement(By.linkText("22014")).click();
    driver.findElement(By.xpath("//a[contains(text(),' BSN - Tpicos Avanados / Turma   4 / Fase 8')]"))
            .click();
    driver.findElement(By.linkText("Trabalhos")).click();
    driver.findElement(By.xpath("//div[@id='svMenuTrabalhos']/ul/li[5]/a/span[2]")).click();
    driver.findElement(By.xpath("//div[@id='salacontainer']/a/span[2]")).click();
    driver.findElement(By.id("titulo")).click();
    driver.findElement(By.id("titulo")).clear();
    driver.findElement(By.id("titulo")).sendKeys("testeSelenium2");
    driver.findElement(By.id("arquivo")).sendKeys("C:\\Users\\Marcos\\Desktop\\55.txt");
    driver.findElement(By.id("grupo")).click();
    new Select(driver.findElement(By.id("grupo"))).selectByVisibleText("Novo Pasta");
    driver.findElement(By.cssSelector("option[value=\"novo\"]")).click();
    driver.findElement(By.id("nomenovogrupo")).click();
    driver.findElement(By.id("nomenovogrupo")).clear();
    driver.findElement(By.id("nomenovogrupo")).sendKeys("teste4");
    driver.findElement(By.name("cadastrar")).click();
    driver.findElement(By.name("cadastrar")).click();

}

From source file:SeleniumLogger.SeleniumLog.java

private void TakeScreenshot(WebDriver drv, String path) throws IOException, AWTException {
    Rectangle bounds = new Rectangle();
    org.openqa.selenium.Point loc = drv.manage().window().getPosition();
    org.openqa.selenium.Dimension dim = drv.manage().window().getSize();
    bounds.setBounds(loc.getX(), loc.getY(), dim.getWidth(), dim.getHeight());

    Robot robot = new Robot();
    BufferedImage screenShot = robot.createScreenCapture(bounds);
    ImageIO.write(screenShot, "JPG", new File(path));
}

From source file:seleniumStudy.SeleniumTest1.java

public static void main(String[] args) throws InterruptedException, IOException {
    System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
    WebDriver driver = new InternetExplorerDriver();
    Timeouts timeout = driver.manage().timeouts();

    Navigation navigation = driver.navigate();
    navigation.to("http://pond.morningstar.com/index.php?c=China&cn=China");
    //        timeout.pageLoadTimeout(30, java.util.concurrent.TimeUnit.SECONDS);
    //        timeout.pageLoadTimeout(30, java.util.concurrent.TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 20);

    WebElement sign = driver.findElement(By.linkText("Sign In"));
    sign.click();/*  ww  w. j  a  v  a 2  s  .  c o m*/
    WebElement username = driver.findElement(By.name("log"));
    username.sendKeys("asun");
    WebElement pwd = driver.findElement(By.name("pwd"));
    pwd.sendKeys("Kwan_9123");
    WebElement login = driver.findElement(By.id("go_submit"));
    //        WebElement login = driver.findElement(By.cssSelector("css=#go_submit"));    
    login.click();
    wait.until(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver d) {
            return d.findElement(By.name("input"));
        }
    }).sendKeys("adrian sun");

    WebElement go = driver.findElement(By.id("go"));
    go.click();

    Runtime runTime = Runtime.getRuntime();
    runTime.exec("tskill iexplore");
    runTime.exec("tskill IEDriverServer");
    //        driver.close();
}

From source file:SmokeTests.Settings.BrowserSettings.java

@BeforeTest
public void setUp(int envIndex, int browserIndex, WebDriver driver) {
    System.out.println("Run WebDriver");
    totalResultMessage += "Run WebDriver\n";
    ProgressBar.addProgressValue(progressVariable);
    driver.manage().window().setSize(new Dimension(1366, 900));
    magentoFSLink = fsEnvironment.get(envIndex);
    driver.get(fsEnvironment.get(envIndex));
    driver.manage().timeouts().implicitlyWait(timeoutVariable, TimeUnit.SECONDS);
}

From source file:snapshot.webdriver.WebDriverHelper.java

License:Open Source License

/**
 * Starts a WebDriver with Screen Dimensions
 *
 * @param driver/*from  w  w  w. j a v a2s .  c  o m*/
 * @param url
 * @param size
 * @return
 */
public static WebDriver setupDriver(WebDriver driver, String url, WindowSize size) {
    driver.manage().window().setPosition(new Point(0, 0));
    driver.manage().window().setSize(new Dimension(size.getWidth().intValue(), size.getHeight().intValue()));
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get(url);
    return driver;
}

From source file:streaming.crawler.WebDriverResource.java

License:Apache License

private WebDriver doCreateWebDriver(boolean headless, String browserType,
        Class<? extends WebDriver> defaultWebDriverClass, Long pageLoadTimeout, Long scriptTimeout,
        Long implicitlyWait//  www  . ja va 2s. c o  m

) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

    DesiredCapabilities capabilities = new DesiredCapabilities(DEFAULT_CAPABILITIES);
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.merge(DEFAULT_CHROME_CAPABILITIES);
    // Use headless mode by default, GUI mode can be used for debugging
    chromeOptions.setHeadless(headless);
    if (headless) {
        // Do not downloading images in headless mode
        chromeOptions.addArguments("--blink-settings=imagesEnabled=false");
    }

    // Reset proxy
    capabilities.setCapability(CapabilityType.PROXY, (Object) null);
    chromeOptions.setCapability(CapabilityType.PROXY, (Object) null);

    // Choose the WebDriver
    WebDriver driver;
    if (browserType == BrowserType.CHROME) {
        driver = new ChromeDriver(chromeOptions);
    } else {
        if (RemoteWebDriver.class.isAssignableFrom(defaultWebDriverClass)) {
            driver = defaultWebDriverClass.getConstructor(Capabilities.class).newInstance(capabilities);
        } else {
            driver = defaultWebDriverClass.getConstructor().newInstance();
        }
    }

    // Set timeouts
    WebDriver.Timeouts timeouts = driver.manage().timeouts();
    timeouts.pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS);
    timeouts.setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);
    timeouts.implicitlyWait(implicitlyWait, TimeUnit.SECONDS);

    // Set log level
    if (driver instanceof RemoteWebDriver) {
        RemoteWebDriver remoteWebDriver = (RemoteWebDriver) driver;

        final Logger webDriverLog = LoggerFactory.getLogger(WebDriver.class);
        Level level = Level.FINE;
        if (webDriverLog.isDebugEnabled()) {
            level = Level.FINER;
        } else if (webDriverLog.isTraceEnabled()) {
            level = Level.ALL;
        }

        remoteWebDriver.setLogLevel(level);
    }

    return driver;
}

From source file:swift.selenium.WaitTool.java

License:Open Source License

public static WebElement waitForElementByWebElement(WebDriver driver, WebElement element,
        int timeOutInSeconds) {

    try {//  w  ww.  j a v  a 2  s .  c  o m
        //To use WebDriverWait(), we would have to nullify implicitlyWait(). 
        //Because implicitlyWait time also set "driver.findElement()" wait time.  
        //info from: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() 

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        element = wait.until(elementToBeClickable(element, ""));

        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return element; //return the element   
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:test.chrome.ChromeTest.java

License:Open Source License

public static void chrome(String baseurl, boolean useKeycloak) {

    WebDriver driver = null;
    try {//from   w ww  . j  a  v a2 s.  c  om
        DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
        desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        desiredCapabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, false);

        ChromeDriverManager.getInstance().setup();
        driver = new ChromeDriver(desiredCapabilities);
        driver.manage().window().setSize(new Dimension(Utils.WINDOW_WIDTH, Utils.WINDOW_HEIGHT));
        driver.manage().timeouts().implicitlyWait(Utils.DEFAULT_WAITING_TIME, TimeUnit.SECONDS);

        TestScenario.useKeycloak = useKeycloak;
        TestScenario.test(driver, baseurl);
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:test.firefox.FirefoxTest.java

License:Open Source License

public static void firefox(String baseurl, boolean useKeycloak) {
    WebDriver driver = null;
    try {/*from  ww w  .j  a v  a2  s.c  om*/
        ProfilesIni allProfiles = new ProfilesIni();
        FirefoxProfile myProfile = allProfiles.getProfile("default");
        myProfile.setAcceptUntrustedCertificates(true);
        myProfile.setAssumeUntrustedCertificateIssuer(false);
        FirefoxDriverManager.getInstance().setup();
        driver = new FirefoxDriver(myProfile);
        driver.manage().window().setSize(new Dimension(Utils.WINDOW_WIDTH, Utils.WINDOW_HEIGHT));
        driver.manage().timeouts().implicitlyWait(Utils.DEFAULT_WAITING_TIME, TimeUnit.SECONDS);

        TestScenario.useKeycloak = useKeycloak;
        TestScenario.test(driver, baseurl);
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:test.TestScenario.java

License:Open Source License

public static void test(WebDriver driver, String baseurl) {

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.get(baseurl);//from w  ww .  j  a  v a 2s.c o m

    navigation = new TestNavigation(driver);

    testLoginLogout(driver);

    testNavigation();

    testCreation(driver);

    testSubscription(driver);

}