/** * 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)); }
/** * 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)); }
/** * 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)); }
@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); } }
@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); } }
@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); } }
@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); } }
/** * 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)); }
/** * 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); }
@Override protected void parseTitle() { title = browser.getWebDriver().getTitle(); // browser.log().debug(" TITLE: " + content.getTitle()); }
@Override protected void parseVisibleText() { // TODO visible text without html tags visibleText = browser.query(QueryFactory.select("body")).findFirst().getText(); // browser.log().debug(content.getVisibleText()); }
@Override protected void parseUrl() { url = browser.getCurrentUrl(); }
public HtmlParser(Browser browser) { super(browser.getWebDriver().getPageSource()); this.browser = browser; }