driver.getPageSource() 将符号 < 转换为 <
driver.getPageSource() converts signs < to <
我正在使用 WebDriver 和 java 来获取页面源代码。使用 FirefoxDriver 我试图验证页面源上的一些文本,但是当我使用 driver.getPageSource 时,它会将一些符号(例如 < 转换为 $lt;和 > 到 > 因为我很难验证内容。
有人可以指导我如何避免这种情况吗?
<noscript>
<div id="noScriptContainer">
<p>JavaScript is not enabled! Either you have disabled it or your browser does not support it. Because of this, you will not be able to view our pages or use our site features. Please turn on JavaScript in your browser settings or upgrade your browser version to use our site. </p>
</div>
</noscript>
转换为=
<noscript>
<div id="noScriptContainer">
<p>JavaScript is not enabled! Either you have disabled it or your browser does not support it. Because of this, you will not be able to view our pages or use our site features. Please turn on JavaScript in your browser settings or upgrade your browser version to use our site. </p>
</div>
一般最好不要使用WebDriver的getPageSource()方法,而是使用JavaScriptExecutor通过javascript获取页面源。
String pageSource = ((JavaScriptExecutor)driver).executeScript("return document.documentElement.outerHTML;").toString();
是的,这是子元素的问题。您可以使用已经告诉过的 javascript 或 url 解码您得到的内容并接收初始源代码。
String result = java.net.URLDecoder.decode(url, "UTF-8");
我正在使用 WebDriver 和 java 来获取页面源代码。使用 FirefoxDriver 我试图验证页面源上的一些文本,但是当我使用 driver.getPageSource 时,它会将一些符号(例如 < 转换为 $lt;和 > 到 > 因为我很难验证内容。
有人可以指导我如何避免这种情况吗?
<noscript>
<div id="noScriptContainer">
<p>JavaScript is not enabled! Either you have disabled it or your browser does not support it. Because of this, you will not be able to view our pages or use our site features. Please turn on JavaScript in your browser settings or upgrade your browser version to use our site. </p>
</div>
</noscript>
转换为=
<noscript>
<div id="noScriptContainer">
<p>JavaScript is not enabled! Either you have disabled it or your browser does not support it. Because of this, you will not be able to view our pages or use our site features. Please turn on JavaScript in your browser settings or upgrade your browser version to use our site. </p>
</div>
一般最好不要使用WebDriver的getPageSource()方法,而是使用JavaScriptExecutor通过javascript获取页面源。
String pageSource = ((JavaScriptExecutor)driver).executeScript("return document.documentElement.outerHTML;").toString();
是的,这是子元素的问题。您可以使用已经告诉过的 javascript 或 url 解码您得到的内容并接收初始源代码。
String result = java.net.URLDecoder.decode(url, "UTF-8");