Example usage for org.openqa.selenium WebElement clear

List of usage examples for org.openqa.selenium WebElement clear

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement clear.

Prototype

void clear();

Source Link

Document

If this element is a form entry element, this will reset its value.

Usage

From source file:io.tourniquet.pageobjects.DynamicElementGroupInterceptor.java

License:Apache License

@Override
public Object intercept(final Object o, final Method method, final Object[] objects,
        final MethodProxy methodProxy) throws Throwable {

    if (Modifier.isAbstract(method.getModifiers())) {
        if (elements.containsKey(method)) {
            WebElement element = elements.get(method).get();
            if ("form".equals(element.getTagName())) {
                element.submit();//  w w  w  . ja v a2s.  c om
            } else if (objects.length == 1) {
                element.clear();
                element.sendKeys(objects[0].toString());
            } else if (objects.length == 0) {
                element.click();
            } else {
                throw new IllegalArgumentException("Method does not match web element " + element);
            }
            if (method.getReturnType().isAssignableFrom(o.getClass())) {
                return o;
            } else if (method.getReturnType().isAssignableFrom(WebElement.class)) {
                return element;
            }
            return null;

        } else {
            throw new NoSuchMethodException("Method " + method + " does not provide locator information");
        }

    }
    return methodProxy.invokeSuper(o, objects);
}

From source file:javax.portlet.tck.driver.TCKSimpleTestDriver.java

License:Apache License

/**
 * Called to login to the portal if necessary. 
 */// w w w .  j ava 2s . c o  m
protected static void login() {

    driver.get(loginUrl);

    List<WebElement> uels = driver.findElements(By.id(usernameId));
    List<WebElement> pwels = driver.findElements(By.id(passwordId));

    // If there is no login or password fields, don't need to login.
    if (!uels.isEmpty() && !pwels.isEmpty()) {

        System.out.println("   No userid / password fields");
        WebElement userEl = uels.get(0);
        WebElement pwEl = pwels.get(0);

        // perform login
        userEl.clear();
        userEl.sendKeys(username);
        pwEl.clear();
        pwEl.sendKeys(password);
        pwEl.submit();

    }
}

From source file:jhc.redsniff.webdriver.SeleniumController.java

License:Apache License

@Override
public void clear(WebElement element) {
    element.clear();
}

From source file:jp.vmi.selenium.selenese.command.AttachFile.java

License:Apache License

@Override
protected Result executeImpl(Context context, String... curArgs) {
    String name = curArgs[ARG_FILENAME];
    File outputTo = null;/*from  www. ja  v a2 s.c o  m*/
    if (name.contains("://")) {
        // process (remote) url
        URL url;
        try {
            url = new URL(name);
        } catch (MalformedURLException e) {
            return new Error("Malformed URL: " + name);
        }
        File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("attachFile", "dir");
        outputTo = new File(dir, new File(url.getFile()).getName());
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(outputTo);
            Resources.copy(url, fos);
        } catch (IOException e) {
            return new Error("Can't access file to upload: " + url, e);
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                return new Warning("Unable to close stream used for reading file: " + name, e);
            }
        }
    } else {
        // process file besides testcase file
        outputTo = new File(FilenameUtils.getPath(context.getCurrentTestCase().getFilename()), name);
        if (!outputTo.exists()) {
            return new Error("Can't access file: " + outputTo);
        }
    }

    WebElement element = context.findElement(curArgs[ARG_LOCATOR]);
    try {
        element.clear();
    } catch (Exception e) {
        // ignore exceptions from some drivers when file-input cannot be cleared;
    }
    element.sendKeys(outputTo.getAbsolutePath());
    return SUCCESS;
}

From source file:lenguajes.project.GUI.java

/**
 * Creates new form GUI//from ww w.  java  2 s  .  c o 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();
    String value;// w w  w .  j a va2 s .co m
    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:loblaw.provisioning.TicketCreator.java

private void createTicket() {
    try {/*  w w  w.  java  2  s.c o m*/

        //   WebElement templateDropdown = (new WebDriverWait(activeBrowser, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"reqTemplateListh\"]/p/span")));
        //  templateDropdown.click();
        //WebElement loblawLine = (new WebDriverWait(activeBrowser, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"reqTemplateList\"]/div/table/tbody/tr/td/ul/li[45]/a")));
        //loblawLine.click();
        Thread.sleep(300);
        WebElement contactName = (new WebDriverWait(activeBrowser, 10)) //added this line
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"reqSearch\"]")));
        contactName.sendKeys("Loblaw");

        WebElement storeNumberArea = (new WebDriverWait(activeBrowser, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"UDF_CHAR2\"]"))));
        storeNumberArea.clear();
        storeNumberArea.sendKeys(storeNumberText);

        WebElement titleArea = (new WebDriverWait(activeBrowser, 10))
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"title\"]")));
        //title format: Loblaw New Site Provisioning - SiteID: [Banner] [Location ID] [Line of Business]
        titleArea.clear();
        titleArea.sendKeys(ticketTitleText);

        WebElement descriptionArea = (new WebDriverWait(activeBrowser, 10)).until(
                ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"zEditor\"]/div/iframe")));
        descriptionArea.sendKeys(Keys.chord(Keys.CONTROL, "a"));
        descriptionArea.sendKeys(ticketDumpText);

        WebElement addRequestButton = (new WebDriverWait(activeBrowser, 10))
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"buttonType\"]")));
        addRequestButton.click();
        Thread.sleep(2000);

    } catch (Exception e) {

        System.out.println("Trying to create ticket, got error:");
        System.out.println(e.getMessage());
    }
}

From source file:Logic.GlassdoorScraper.java

public void fetchJobs(String url) {
    try {// w  w w . j  a  v  a 2 s  . c om
        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:login.CreateUsers.java

License:Open Source License

protected boolean isUserCreated(String userAndGroupLink, String username) {
    driver.findElement(By.linkText(userAndGroupLink)).click();
    // search the user
    WebElement searchTextInput = driver.findElement(By.id("searchForm:searchText"));
    searchTextInput.clear();
    searchTextInput.sendKeys(username);//from  www .  ja v  a2  s .co m
    driver.findElement(By.id("searchForm:searchButton")).click();
    try {
        driver.findElement(By.linkText(username));
    } catch (NoSuchElementException e) {
        return false;
    }
    return true;
}

From source file:loteriaNacional.RobotLoteria.java

public void comprobar(int numero, float dinero) {
    // Introducimos el nmero y la cantidad de dinero en sus respectivos campos
    WebElement n = driver.findElement(By.id("numero"));
    n.sendKeys(numero + "");
    WebElement e = driver.findElement(By.id("cantidad"));
    // Borramos el contenido por defecto de la cantidad
    e.clear();
    e.sendKeys(dinero + "");

    // Nos posicionamos, para que todo funcione correcto
    // Si lo quito --> falla
    driver.findElement(By.className("cuerpoRegion"));

    // Como no tenemos ninguna forma de identificar al botn vamos a hacerlo con el cssSelector a mano:
    // etiqueta con value = 'nombre' 
    // La siguiente forma sera usando xpath --> no me ha funcionado
    // driver.findElement(By.xpath("//input[contains(text(), 'COMPROBAR')]")).click();
    driver.findElement(By.cssSelector("input[value='COMPROBAR']")).click();

    // nos aseguraremos de que esta accesible el mensaje de salida 
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.className("alerta"))));
    System.out.println(driver.findElement(By.className("alerta")).findElement(By.tagName("p")).getText());
}