【问题标题】:Java Selenium HtmlUnitDriver - Gwt source is not populating due to Ajax callJava Selenium HtmlUnitDriver - 由于 Ajax 调用,未填充 Gwt 源
【发布时间】:2016-04-11 11:15:45
【问题描述】:

我正在使用 Java Selenium HtmlUnitDriver 来验证由于 Ajax 调用而没有填充 Gwt 源的 html。有没有办法执行实际页面并获取页面的来源?我尝试启用Js,但仍然没有成功。

【问题讨论】:

    标签: java selenium junit


    【解决方案1】:

    如果您需要处理动态内容,那么最好的机会可能是使用带有 JavaScript 引擎的浏览器/驱动程序。下面是一个无头 PhantomJS 驱动的例子:

    System.setProperty("phantomjs.binary.path", "...");
    
    WebDriver driver = new PhantomJSDriver();
    WebDriverWait wait = new WebDriverWait(driver, 20);
    
    // load the page
    driver.get("http://...");
    
    // wait for a dynamic element to be created
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("...")));
    
    // get the page source
    String source = driver.getPageSource();
    

    【讨论】:

      猜你喜欢
      • 2017-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      相关资源
      最近更新 更多