gpt4 book ai didi

selenium - InternetExplorerDriver getPageSource() 返回的字符串与 FirefoxDriver 不同

转载 作者:行者123 更新时间:2023-12-01 12:42:35 26 4
gpt4 key购买 nike

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

我正在尝试获取页面的页面源,但我注意到 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?

最佳答案

不,那是因为 getPageSource 方法不像在浏览器中手动那样返回页面源,而是返回 DOM 的文本表示。 Javadoc of getPageSource更好地解释它:

java.lang.String getPageSource()

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.

关于selenium - InternetExplorerDriver getPageSource() 返回的字符串与 FirefoxDriver 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17734065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com