InternetExplorerDriver getPageSource() 返回的字符串与 FirefoxDriver 不同 [英] InternetExplorerDriver getPageSource() is returning a different string than FirefoxDriver

查看:27
本文介绍了InternetExplorerDriver getPageSource() 返回的字符串与 FirefoxDriver 不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Selenium 的新手,想知道是否有人可以为我指明正确的方向.

I am new to Selenium and wonder if someone could point me in the right direction.

我正在尝试获取页面的页面源,但我注意到 IE 驱动程序返回了一些内容与 FirefoxDriver 不同.

I am trying to get the page source of a page, but I notice IE driver returns something different than FirefoxDriver.

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

Also, the String returned by InternetExplorerDriver.getPageSource() is different than the one i see if i click view page source on IE.

我运行的是 IE 8 和 Firefox 22.

I am running IE 8 and Firefox 22.

此页面上的示例:http://stackoverflow.com/questions/16455217/webdriver-save-the-location-of-the-id-in-the-page

当我调用 getPageSource() 时,IE 返回了类似的内容.

When I called getPageSource(), IE returned something like this.

"<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 返回了这个.

While Firefox returned this.

"<!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?

Is there a way for IEDriver to return a pageSource in the same way as FirefoxDriver?

推荐答案

不,那是因为 getPageSource 方法不会像在浏览器中手动那样返回页面源,而是返回文本表示DOM 的. 的 JavadocgetPageSource 解释得更好:

No, that's because the getPageSource method does not return the page source as it would do manually in your browser but returns a text representation of the DOM. Javadoc of getPageSource explains it better:

java.lang.String getPageSource()

获取上次加载页面的来源.如果页面被修改加载后(例如,通过 Javascript)无法保证返回的文本是修改后的页面的文本.请咨询用于确定特定驱动程序的文档返回的文本反映了页面或文本的当前状态最后由网络服务器发送.返回的页面源是一个底层 DOM 的表示:不要期望它被格式化或以与从 Web 服务器发送的响应相同的方式转义.将其视为艺术家的印象.

Get the source of the last loaded page. If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page. Please consult the documentation of the particular driver being used to determine whether the returned text reflects the current state of the page or the text last sent by the web server. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server. Think of it as an artist's impression.

这篇关于InternetExplorerDriver getPageSource() 返回的字符串与 FirefoxDriver 不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆