2013-07-18 19 views
2

我是Selenium的新手,想知道是否有人能指出我正确的方向。InternetExplorerDriver getPageSource()返回的字符串不同于FirefoxDriver

我想获取页面的页面源,但我注意到IE驱动程序返回的东西 不同于FirefoxDriver。

此外,InternetExplorerDriver.getPageSource()返回的字符串与我在IE上单击查看页面源时看到的字符串不同。

我运行IE 8和Firefox 22

对于样品此页上:http://stackoverflow.com/questions/16455217/webdriver-save-the-location-of-the-id-in-the-page

当我打电话getPageSource(),IE返回类似这样的。

"<HTML><HEAD><TITLE>selenium - Webdriver/Save the location of the ID in the page - Stack Overflow</TITLE><LINK rel="shortcut icon" href="https://cdn.sstatic.net/stackoverflow/img/favicon.ico"><LINK rel="apple-touch-icon image_src" href="https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png"> 

虽然Firefox返回了这个。

"<!DOCTYPE html> 

<title>selenium - Webdriver/Save the location of the ID in the page - Stack Overflow</title> 
<link href="https://cdn.sstatic.net/stackoverflow/img/favicon.ico" rel="shortcut icon" /> 
<link href="https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png" rel="apple-touch-icon image_src" /> 

是否有IEDriver的方式相同的方式为FirefoxDriver返回pageSource?

回答

6

不,这是因为getPageSource方法不会返回页面源代码,因为它会在浏览器中手动执行,但会返回DOM的文本表示形式。 Javadoc of getPageSource更好地解释它:

java.lang.String getPageSource()

获取最后加载页面的源代码。如果页面在加载(例如,通过Javascript)后被修改为 ,则不能保证 返回的文本是修改页面的文本。请参阅 正在使用的特定驱动程序的文档,以确定返回的文本是否反映了网页当前的状态或上次由Web服务器发送的文本 。 返回的页面源代码是一个 表示底层的DOM:不要期望它被格式化为 或以与从Web服务器发送的响应相同的方式转义。 把它当作艺术家的印象。

相关问题