Search in sources :

Example 21 with RuntimeException

use of java.lang.RuntimeException in project selenium_java by sergueik.

the class AppTest method findElement.

private WebElement findElement(String selectorKind, String selectorValue) {
    WebElement element = null;
    Hashtable<String, Boolean> supportedSelectorStrategies = new Hashtable<String, Boolean>();
    supportedSelectorStrategies.put("id", true);
    supportedSelectorStrategies.put("css_selector", true);
    supportedSelectorStrategies.put("xpath", true);
    supportedSelectorStrategies.put("partial_link_text", false);
    supportedSelectorStrategies.put("link_text", true);
    supportedSelectorStrategies.put("classname", false);
    if (selectorKind == null || !supportedSelectorStrategies.containsKey(selectorKind) || !supportedSelectorStrategies.get(selectorKind)) {
        return null;
    }
    if (selectorKind == "id") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(selectorValue)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.id(selectorValue));
    }
    if (selectorKind == "classname") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(selectorValue)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.className(selectorValue));
    }
    if (selectorKind == "link_text") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText(selectorValue)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.linkText(selectorValue));
    }
    if (selectorKind == "css_selector") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(selectorValue)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.cssSelector(selectorValue));
    }
    if (selectorKind == "xpath") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(selectorValue)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.xpath(selectorValue));
    }
    return element;
}
Also used : RuntimeException(java.lang.RuntimeException) Hashtable(java.util.Hashtable) WebElement(org.openqa.selenium.WebElement) Boolean(java.lang.Boolean)

Example 22 with RuntimeException

use of java.lang.RuntimeException in project selenium_java by sergueik.

the class App method find_element.

// http://selenium-interview-questions.blogspot.in/2014/02/how-to-take-screenshot-of-webpage-using.html
// http://www.adam-bien.com/roller/abien/entry/named_parameters_in_java_8
// does nothing exist prior to java 8 ?
private WebElement find_element(String selector_type, String selector_value) {
    int flexible_wait_interval = 5;
    long wait_polling_interval = 500;
    WebDriverWait wait = new WebDriverWait(driver, flexible_wait_interval);
    wait.pollingEvery(wait_polling_interval, TimeUnit.MILLISECONDS);
    WebElement element = null;
    Hashtable<String, Boolean> supported_selectors = new Hashtable<String, Boolean>();
    supported_selectors.put("id", true);
    supported_selectors.put("css_selector", true);
    supported_selectors.put("xpath", true);
    supported_selectors.put("partial_link_text", true);
    supported_selectors.put("link_text", true);
    supported_selectors.put("classname", true);
    supported_selectors.put("tag_name", true);
    if (selector_type == null || !supported_selectors.containsKey(selector_type) || !supported_selectors.get(selector_type)) {
        return null;
    }
    if (selector_type == "id") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(selector_value)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.id(selector_value));
    }
    if (selector_type == "classname") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(selector_value)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.className(selector_value));
    }
    if (selector_type == "tag_name") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName(selector_value)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.tagName(selector_value));
    }
    if (selector_type == "link_text") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText(selector_value)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.linkText(selector_value));
    }
    if (selector_type == "partial_link_text") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.partialLinkText(selector_value)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.partialLinkText(selector_value));
    }
    if (selector_type == "css_selector") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(selector_value)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.cssSelector(selector_value));
    }
    if (selector_type == "xpath") {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(selector_value)));
        } catch (RuntimeException timeoutException) {
            return null;
        }
        element = driver.findElement(By.xpath(selector_value));
    }
    return element;
}
Also used : RuntimeException(java.lang.RuntimeException) Hashtable(java.util.Hashtable) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 23 with RuntimeException

use of java.lang.RuntimeException in project CoreNLP by stanfordnlp.

the class TokenSequenceParser method ReInit.

/**
 * Reinitialise.
 */
public void ReInit(java.io.InputStream stream, String encoding) {
    try {
        jj_input_stream.ReInit(stream, encoding, 1, 1);
    } catch (java.io.UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 71; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
Also used : RuntimeException(java.lang.RuntimeException)

Aggregations

RuntimeException (java.lang.RuntimeException)23 IOException (java.io.IOException)11 CipherInputStream (javax.crypto.CipherInputStream)9 WebElement (org.openqa.selenium.WebElement)7 Hashtable (java.util.Hashtable)4 Cipher (javax.crypto.Cipher)4 File (java.io.File)3 Exception (java.lang.Exception)3 Throwable (java.lang.Throwable)3 AEADBadTagException (javax.crypto.AEADBadTagException)3 Test (org.junit.Test)3 FileNotFoundException (java.io.FileNotFoundException)2 Boolean (java.lang.Boolean)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 SearchContext (org.openqa.selenium.SearchContext)2 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)2 SuppressLint (android.annotation.SuppressLint)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 TransactionTooLargeException (android.os.TransactionTooLargeException)1 BufferedReader (java.io.BufferedReader)1