Search in sources :

Example 1 with ElementHandle

use of com.ruiyun.jvppeteer.core.page.ElementHandle in project epic4j by huisunan.

the class PageUtil method waitForTextChange.

@SneakyThrows
public void waitForTextChange(Page page, String selector, String text, Integer timeout, Integer interval) {
    timer(timeout, interval, i -> {
        ElementHandle elementHandle = page.$(selector);
        log.trace("wait {} text change count {}", selector, i);
        if (elementHandle != null) {
            String textContent = getElementStrProperty(elementHandle, "textContent");
            log.trace("textContent:{}", textContent);
            return !text.equalsIgnoreCase(textContent);
        }
        return false;
    }, () -> {
        throw new TimeException("wait text change timeout :" + text);
    });
}
Also used : TimeException(com.hsn.epic4j.core.exception.TimeException) ElementHandle(com.ruiyun.jvppeteer.core.page.ElementHandle) SneakyThrows(lombok.SneakyThrows)

Example 2 with ElementHandle

use of com.ruiyun.jvppeteer.core.page.ElementHandle in project epic4j by huisunan.

the class PageUtil method elementHandle.

@SneakyThrows
public void elementHandle(Page page, String selector, Integer timeout, Integer interval, EConsumer<ElementHandle> consumer) {
    timer(timeout, interval, i -> {
        log.trace("[{}]wait for selector:{}", i, selector);
        ElementHandle elementHandle = page.$(selector);
        if (elementHandle != null) {
            log.trace("start consumer");
            consumer.accept(elementHandle);
            log.trace("end consumer");
            // 点击后延迟2秒等待处理
            TimeUnit.SECONDS.sleep(2);
            return true;
        }
        return false;
    }, () -> {
        throw new TimeoutException("wait for selector " + selector + " time out");
    });
}
Also used : ElementHandle(com.ruiyun.jvppeteer.core.page.ElementHandle) TimeoutException(java.util.concurrent.TimeoutException) SneakyThrows(lombok.SneakyThrows)

Example 3 with ElementHandle

use of com.ruiyun.jvppeteer.core.page.ElementHandle in project epic4j by huisunan.

the class PageUtil method elementHandle.

@SneakyThrows
public void elementHandle(Page page, String selector, Integer timeout, Integer sleep, EConsumer<ElementHandle> consumer) {
    ElementHandle elementHandle = page.waitForSelector(selector, SelectorUtil.timeout(ObjectUtil.defaultIfNull(timeout, 30000)));
    consumer.accept(elementHandle);
    TimeUnit.MILLISECONDS.sleep(ObjectUtil.defaultIfNull(sleep, 2000));
}
Also used : ElementHandle(com.ruiyun.jvppeteer.core.page.ElementHandle) SneakyThrows(lombok.SneakyThrows)

Example 4 with ElementHandle

use of com.ruiyun.jvppeteer.core.page.ElementHandle in project epic4j by huisunan.

the class PageUtil method waitForTextChange.

@SneakyThrows
public Boolean waitForTextChange(Page page, String selector, String text, Integer timeout, Integer interval) {
    for (int i = 0; i < timeout; i += interval) {
        ElementHandle elementHandle = page.$(selector);
        log.trace("wait {} text change count {}", selector, i);
        if (elementHandle != null) {
            String textContent = getElementStrProperty(elementHandle, "textContent");
            if (!text.equals(textContent)) {
                return true;
            }
        }
        TimeUnit.MILLISECONDS.sleep(interval);
    }
    throw new TimeException("wait text change timeout :" + text);
}
Also used : TimeException(com.hsn.epic4j.exception.TimeException) ElementHandle(com.ruiyun.jvppeteer.core.page.ElementHandle) SneakyThrows(lombok.SneakyThrows)

Aggregations

ElementHandle (com.ruiyun.jvppeteer.core.page.ElementHandle)4 SneakyThrows (lombok.SneakyThrows)4 TimeException (com.hsn.epic4j.core.exception.TimeException)1 TimeException (com.hsn.epic4j.exception.TimeException)1 TimeoutException (java.util.concurrent.TimeoutException)1