我编写了一个在java中运行的selenium脚本:
String pageName = "my test url which invloves an link to html which has javscript excution";
logger.log(Level.INFO,"Page name : " + pageName);
WebDriver driver = new HtmlUnitDriver(true);
logger.log(Level.INFO,"driver instance created " );
String str ="";
logger.log(Level.INFO,"opening the url now.... " );
driver.get(pageName);
logger.log(Level.INFO,"url is now opened :: url = "+driver.getCurrentUrl());
logger.log(Level.INFO,"driver now going to sleep = "+driver.getCurrentUrl());
Thread.sleep(150000);
logger.log(Level.INFO,"Wake up from sleep now....");
logger.log(Level.INFO,"URL ::"+driver.getCurrentUrl());
logger.log(Level.INFO,"PageSource ::"+driver.getPageSource());
try {
logger.log(Level.INFO,"Driver going to wait now...");
driver.wait(100000);
logger.log(Level.INFO,"Driver came out of wait now normally...");
} catch (Exception e) {
logger.log(Level.INFO,"Driver came out of wait now exception::"+e);
}
logger.log(Level.INFO,"driver instance task completed " );
logger.log(Level.INFO,driver.getCurrentUrl());
logger.log(Level.INFO,driver.getCurrentUrl());
logger.log(Level.INFO,str);
driver.close();
现在,当我调试这段代码时,我得到了正确的结果,但是当我从servlet运行这段代码时,我只得到了html内容,而不是来自给定链接的正常内容。
我也试过使用firefox驱动程序,相同的代码可以正常使用它。 我也尝试过与Web客户端相同的代码,但同样的问题即将来临。
任何人都可以帮我解决这个例外吗?
谢谢,
答案 0 :(得分:0)
调试代码时,可以在检查点停止。但是你无法阻止浏览器加载。它独立加载自身。 Htmlunitdriver pagesource返回所有html内容,因为它无法完全执行javascript。如果htmlpage包含Ajax,javascript调用则会显示调用。