0
を使用してGWTアプリケーションのJavaScriptを有効にすることはできません。最初に私は次のように、HtmlUnitDriverを使用して、ページの内容を取得しようとしました:は、セレンのWebClientまたは私は<strong>ヘッドレスブラウザのテスト</strong>を使用して<strong>GWTアプリケーション</strong>のためのGUIをテストするために、HTMLページのソースを取得しようとしていますHtmlUnitDriver
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
//set an userId header
capabilities.setCapability("id", "userId");
HtmlUnitDriver unitDriver = new HtmlUnitDriver(capabilities);
//enabled javascript
unitDriver.setJavascriptEnabled(true);
unitDriver.get("http://localhost:portNo/example/");
String pageSource = unitDriver.getPageSource();
それを行うための第二の方法は、Webクライアントを使用していた:で、
WebClient webClient = new WebClient();
//enabled javascript
webClient.getOptions().setJavaScriptEnabled(true);
//set an userId header
webClient.addRequestHeader("id", "userId");
HtmlPage page = webClient.getPage("http://localhost:portNo/example/");
String contentAsString = page.getWebResponse().getContentAsString();
しかし、どちらの場合も同じ結果が得られます。結果ページの実際のコンテンツが含まれていない、それは次のように表示されます。
</iframe>
<!-- RECOMMENDED if your web app will not function without JavaScript enabled --> <noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
<iframe src="javascript:''" id="frameId" style="position:absolute;width:0;height:0;border:none" tabindex="-1">
</iframe>
は、私が何かできることはあります/ページの実際のコンテンツを取得するために有効にしますか?ありがとうございました!
unitDriver.getPafeSource()とpage.getWebReponse()の両方がホストページコンテンツを返しています(http://www.gwtproject.org/doc/latest/DevGuideOrganizingProjects.html#DevGuideHostPageを参照)。これは実際のコンテンツです。しかし、ブートストラップ後にいくつかの要素をチェックしたいと思う。この場合、HtmlUnit/WebClientのDOM関連APIを使用する必要があります(例:page.asText、page.getByXpath) –
Alexanderさん、ありがとうございます。あなたは正しいです、私はページ内のDOM要素を探していますが、問題はunitDriver.findElementByClassName( "listGrid")などを呼び出すときに何も得られないということです。また、page.asText()メソッドはページタイトルのみを提供するので、あまり有用ではありません。 –