Example #1
0
  /**
   * Waits until the specified JavaScript returns a non-false value.
   *
   * @param expression the JavaScript expression to evaluate
   * @param timeout time in seconds to wait until a TimeoutException is thrown
   * @throws TimeoutException
   */
  public void evaluatedJavaScriptExpression(String expression, int timeout)
      throws TimeoutException {
    WebDriverWait wait = new WebDriverWait(browser.getWebDriver(), timeout);

    // start waiting for adequate evaluation of expression
    wait.until(new JavaScriptEvaluatedWaitCondition(browser, expression));
  }
Example #2
0
  /**
   * Waits until element contains the specified text. Useful for waiting for an AJAX call to
   * complete.
   *
   * @param element the element to observe
   * @param text when the element contains this text the execution of the program will be continued
   * @throws TimeoutException
   */
  public void elementText(HtmlElement element, String text) throws TimeoutException {
    FluentWait<WebDriver> wait =
        new FluentWait<WebDriver>(browser.getWebDriver())
            .withTimeout(timeout, TimeUnit.SECONDS)
            .pollingEvery(500, TimeUnit.MILLISECONDS);

    // start waiting for given text of element
    wait.until(new ElementHasTextWaitCondition(element, text));
  }
Example #3
0
  /**
   * Waits until element is found. Useful for waiting for an AJAX call to complete.
   *
   * @param query the element query
   * @throws TimeoutException
   */
  public void query(HtmlQuery query) throws TimeoutException {
    //		WebDriverWait wait = new WebDriverWait(browser.getWebDriver(), timeout);
    FluentWait<WebDriver> wait =
        new FluentWait<WebDriver>(browser.getWebDriver())
            .withTimeout(timeout, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.SECONDS);

    // start waiting for given element
    wait.until(new ElementWaitCondition(query));
  }
Example #4
0
 @Override
 protected void parseLinks() {
   // parse links
   HtmlElements linkElements = browser.query(QueryFactory.select("a")).find();
   for (HtmlElement element : linkElements) {
     Link link = new Link();
     link.setUrl(element.getAttribute("href"));
     link.setName(element.getText());
     //			browser.log().debug(" LINK: " + link);
     links.add(link);
   }
 }
Example #5
0
 @Override
 protected void parseHeaders() {
   // parse headers
   HtmlElements headerElements = browser.query(QueryFactory.headline()).find();
   for (HtmlElement element : headerElements) {
     Header header = new Header();
     header.setText(element.getText());
     header.setSize(element.getCssValue("font-size"));
     //			browser.log().debug(" HEADER: " + header);
     headers.add(header);
   }
 }
Example #6
0
 @Override
 protected void parseInputs() {
   // parse forms
   HtmlElements inputElements = browser.query(QueryFactory.typable()).find();
   for (HtmlElement element : inputElements) {
     Input input = new Input();
     input.setLabel(""); // TODO find label
     input.setType(element.getAttribute("type"));
     input.setName(element.getAttribute("name"));
     //			browser.log().debug(" INPUT: " + input);
     inputs.add(input);
   }
 }
Example #7
0
 @Override
 protected void parseImages() {
   // parse images
   HtmlElements imageElements = browser.query(QueryFactory.image()).find();
   for (HtmlElement element : imageElements) {
     Image image = new Image();
     image.setUrl(element.getAttribute("src"));
     image.setTitle(element.getAttribute("title"));
     image.setAlt(element.getAttribute("alt"));
     //			browser.log().debug(" IMAGE: " + image);
     images.add(image);
   }
 }
Example #8
0
 /**
  * Waits until element is found. Useful for waiting for an AJAX call to complete.
  *
  * @param query the element which needs to be found, identified by the visible text or attribute
  *     values
  * @throws TimeoutException
  */
 public void element(String query) throws TimeoutException {
   query(browser.query().has(query));
 }
Example #9
0
 /**
  * Waits until element contains the specified text. Useful for waiting for an AJAX call to
  * complete.
  *
  * @param query the found element should contain the text or attribute value specified here
  * @param text when the element contains this text the execution of the program will be continued
  * @throws TimeoutException
  */
 public void elementText(String query, String text) throws TimeoutException {
   elementText(browser.query().has(query).isText().findFirst(), text);
 }
Example #10
0
 @Override
 protected void parseTitle() {
   title = browser.getWebDriver().getTitle();
   //		browser.log().debug(" TITLE: " + content.getTitle());
 }
Example #11
0
 @Override
 protected void parseVisibleText() {
   // TODO visible text without html tags
   visibleText = browser.query(QueryFactory.select("body")).findFirst().getText();
   //		browser.log().debug(content.getVisibleText());
 }
Example #12
0
 @Override
 protected void parseUrl() {
   url = browser.getCurrentUrl();
 }
Example #13
0
 public HtmlParser(Browser browser) {
   super(browser.getWebDriver().getPageSource());
   this.browser = browser;
 }