Example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated.

Prototype

public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page and visible.

Usage

From source file:juzu.impl.plugin.amd.AmdAdapterTestCase.java

License:Open Source License

@Test
@RunAsClient//  w  w w .j  ava  2  s  .c om
public void test() throws Exception {
    driver.get(applicationURL().toString());
    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html[@foo]")));
    WebElement elt = driver.findElement(By.tagName("html"));
    assertEquals("foo_value", elt.getAttribute("foo"));
}

From source file:juzu.impl.plugin.amd.AmdAliasesTestCase.java

License:Open Source License

@Test
@RunAsClient/*from   w  w w .  j  a v  a2s .  com*/
public void test() throws Exception {
    driver.get(applicationURL().toString());
    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html[@bar]")));
    WebElement elt = driver.findElement(By.tagName("html"));
    assertEquals("<bar>foo_value</bar>", elt.getAttribute("bar"));
}

From source file:juzu.impl.plugin.amd.AmdDependenciesTestCase.java

License:Open Source License

@Test
@RunAsClient//from   w  w w.j  av a 2  s.c  o  m
public void test() throws Exception {
    driver.get(applicationURL().toString());
    System.out.println(driver.getPageSource());
    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html[@bar]")));
    WebElement elt = driver.findElement(By.tagName("html"));
    assertEquals("<bar>foo_value</bar>", elt.getAttribute("bar"));
}

From source file:lenguajes.project.GUI.java

/**
 * Creates new form GUI//w  ww .j av a2s  . co  m
 */
public GUI() {
    initComponents();
    output.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
    output.setCodeFoldingEnabled(true);
    input.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
    input.setCodeFoldingEnabled(true);
    setKeyBindings();
    if (cond) {
        System.setProperty("webdriver.gecko.driver", Config.WEB_DRIVER_PATH);
        //Create object of FirefoxProfile in built class to access Its properties.
        FirefoxProfile fprofile = new FirefoxProfile();
        //Set Location to store files after downloading.
        fprofile.setPreference("browser.download.dir", property + Config.DOWNLOAD_DIR);
        fprofile.setPreference("browser.download.folderList", 2);
        //Set Preference to not show file download confirmation dialogue using MIME types Of different file extension types.
        fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"//MIME types Of MS Excel File.
                        + "application/pdf;" //MIME types Of PDF File.
                        + "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" //MIME types Of MS doc File.
                        + "text/plain;" //MIME types Of text File.
                        + "image/png;" //MIME types Of png Files.
                        + "text/csv"); //MIME types Of CSV File.
        fprofile.setPreference("browser.download.manager.showWhenStarting", false);
        fprofile.setPreference("pdfjs.disabled", true);
        //Pass fprofile parameter In webdriver to use preferences to download file.
        driver = new FirefoxDriver(fprofile);

        driver = new FirefoxDriver(fprofile);
        baseUrl = "http://localhost:7474";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get(baseUrl + "/browser/");
        WebDriverWait wait = new WebDriverWait(driver, 10);
        WebElement element = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.id("connect_password")));
        element.clear();
        element.sendKeys(Config.NEO4J_PASSWORD);
        driver.findElement(By.id("connect_button")).click();
    }
    drawComponents();
}

From source file:lenguajes.project.GUI.java

private void openBrowser(String cypherText) {
    //"div.cm-s-neo > div > textarea" cm-s-neo
    WebElement element = driver.findElement(By.className("view-editor"));
    WebElement custom = element.findElement(By.className("ng-valid"));
    System.out.println(custom.toString());
    WebElement child = custom.findElement(By.className("CodeMirror"));
    System.out.println(child.toString());
    WebElement txArea = child.findElement(By.cssSelector("div > textarea"));
    System.out.println(txArea.toString());
    txArea.clear();//from   www .ja va2s .c  om
    String value;
    cypherText = cypherText.replaceAll("\n", "");
    if (cypherText.contains("return")) {
        value = cypherText;
    } else {
        value = cypherText.replaceAll(";", "") + " return *;";
    }
    try {
        ((JavascriptExecutor) driver).executeScript("arguments[0].value='" + value + "'", txArea);
    } catch (Exception e) {
        System.out.println("weir exception but works");
    }
    System.out.println(txArea.getTagName() + " " + txArea.getAttribute("style") + " text: " + txArea.getText());
    // driver.findElement(By.xpath("//div[@id='stream']/div/div/div/div/div/ul/li[6]/a")).click();
    driver.findElement(By.cssSelector("i.fa.fa-play")).click();

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement download = wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='editor']/div/ul/li[3]/a")));
    download.click();
    driver.findElement(By.xpath("//div[@id='stream']/div/div/div/div/div/ul/li[3]/a")).click();
    driver.findElement(By.linkText("Export PNG")).click();
    driver.findElement(By.xpath("//div[@id='stream']/div/div/div/div/div/ul/li[6]/a")).click();
    try {
        Thread.sleep(3000);
    } catch (InterruptedException ex) {
        Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Logic.GlassdoorScraper.java

public void fetchJobs(String url) {
    try {//from w  ww.  j a v  a 2  s  .  co  m
        setProperty("webdriver.chrome.driver", "C:\\Users\\jason\\Desktop\\Selenium Jars\\chromedriver.exe");
        //setProperty("webdriver.chrome.driver", "C:\\Users\\jleung\\Desktop\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get(url);

        //waits at least 10 seconds for each element before timesout.
        wait = new WebDriverWait(driver, 60);
        //query search
        WebElement querySearch = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='KeywordSearch']")));
        querySearch.sendKeys(query);
        //location search
        WebElement locationSearch = wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='LocationSearch']")));
        locationSearch.clear();
        locationSearch.sendKeys(location);
        locationSearch.sendKeys(Keys.ENTER);
        //submit button
        WebElement submitBtn = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@type='submit']")));
        submitBtn.click();
        //calls upon helper method to grab links and place into list
        grabGlassDoorLinks();
        //iterates to the next tabs of glassdoor jobs to grab their urls as well.
        iterateGlassDoor();
    } catch (NoSuchElementException ex) {
        return;
    }
}

From source file:Logic.GlassdoorScraper.java

private void grabGlassDoorLinks() {
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[@class='jobListing']//div//a")));
    glassDoorLinksList = driver.findElements(xpath("//li[@class='jobListing']//div//span//a"));
    System.out.println("Size of links list is " + glassDoorLinksList.size());
    glassDoorDatesList = driver.findElements(By.xpath("//span[@class='minor nowrap']"));
    System.out.println("Size of Dates List is " + glassDoorDatesList.size());
    for (int i = 0; i < glassDoorLinksList.size(); i++) {
        title = glassDoorLinksList.get(i).getText();
        link = glassDoorLinksList.get(i).getAttribute("href");
        date = glassDoorDatesList.get(i).getText();
        database.addToDataBase(title, link, date, "glassDoorJobs");
    }//from  www  .  j  a va 2 s.  c  om
}

From source file:Logic.GlassdoorScraper.java

private void iterateGlassDoor() {
    for (int i = 2; i < 50; i++) {
        try {/*from  w ww  .  j  a  va 2  s .  co m*/
            ((JavascriptExecutor) driver).executeScript("scroll(0,2300)");
            driver.findElement(xpath("//a[text()=" + i + "]")).click();
            wait.until(ExpectedConditions
                    .visibilityOfElementLocated(By.xpath("//li[@class='jobListing']//div//a")));
            grabGlassDoorLinks();
        }
        //handles the email popup.
        catch (WebDriverException ex) {
            try {
                driver.findElement(xpath("//button[@title='Close (Esc)']")).click();
                wait.until(ExpectedConditions
                        .visibilityOfElementLocated(By.xpath("//li[@class='jobListing']//div//a")));
                grabGlassDoorLinks();
            } catch (ElementNotVisibleException ex2) {
                return;
            }
        }
    }
}

From source file:main.java.qa.android.util.WaitTool.java

License:Open Source License

/**
  * Wait for the element to be present in the DOM, and displayed on the page. 
  * And returns the first WebElement using the given method.
  * //  w  ww.  j  a  v  a2  s . co  m
  * @param WebDriver   The driver object to be used 
  * @param By   selector to find the element
  * @param int   The time in seconds to wait until returning a failure
  *
  * @return WebElement   the first WebElement using the given method, or null (if the timeout is reached)
 * @throws ExpectedExceptions 
  */
public static WebElement waitForElement(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        //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(ExpectedConditions.visibilityOfElementLocated(by));

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

From source file:net.continuumsecurity.web.WebApplication.java

License:Open Source License

public WebElement findAndWaitForElement(By by) {
    try {//from   w  w  w .java2  s . c om
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.visibilityOfElementLocated(by));
    } catch (TimeoutException e) {
        throw new NoSuchElementException(e.getMessage());
    }
    return driver.findElement(by);
}