HtmlUnitDriver ajax无法加载

时间:2018-06-15 10:23:05

标签: ajax htmlunit-driver

我需要加载页面并发送输入字段请求(ajax)。我使用这段代码:

val cookies = ChromeBrowser().getCookiesForDomain(domain) as Set<DecryptedCookie>

val browser = object : HtmlUnitDriver(true)
{
    override fun modifyWebClient(client: WebClient): WebClient
    {
        client.options.isThrowExceptionOnFailingStatusCode = false
        client.options.isThrowExceptionOnScriptError = false
        return client
    }
}

browser.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS)
browser.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS)
browser.manage().timeouts().setScriptTimeout(2, TimeUnit.SECONDS)

browser.get(site)

for(cookie in cookies)
    browser.manage().addCookie(Cookie(cookie.name, cookie.decryptedValue, cookie.path, cookie.expires))

browser.get(site)

browser.findElementById("id-search").sendKeys("3582181")
browser.findElementById("id-search-refresh").click()
waitController.withTimeout(Duration.ofSeconds(10))

println(browser.pageSource)

Ajax conent不在页面源上。求助。

0 个答案:

没有答案