gpt4 book ai didi

javascript - Selenium 驱动程序在 click() 后不反射(reflect)页面变化

转载 作者:行者123 更新时间:2023-11-29 18:08:35 26 4
gpt4 key购买 nike

以下代码返回的源不反射(reflect)调用 click() 后由 javascript 引起的网页变化。我错过了什么?

driver.findElement(By.xpath(xpath)).click(); // changes page content
Thread.sleep(10000);
String src = driver.getPageSource(); // src does not reflect changes

最佳答案

您不应依赖网络驱动程序的 getPageSource() 方法。

来自文档:

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.

Returns: The source of the current page

http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#getPageSource%28%29

关于javascript - Selenium 驱动程序在 click() 后不反射(reflect)页面变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29467990/

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