简体   繁体   中英

Selenium driver does not reflect page changes after click()

The source returned by the following code does not reflect changes in the web page caused by a javascript after calling click(). What am I missing?

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

You should not rely on webdrivers getPageSource() method.

From the docs:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM