Immutable, driver-like snapshot of the current browser page state
🚀 Feature Proposal
tl;dr: Get a snapshot of the DOM, CSS, and layout at a point in time and have access to Selenium's searching tools to better get at the information you're looking for.
Ability to get an object of a snapshot / freeze frame / single point in time for the current browser tab/page state and be able to operate on that snapshot with driver functionality.
- The snapshot would have a subset of driver functionality (the idempotent methods) that can be run against an immutable object, as listed below.
- It would AT LEAST include the current DOM, but would hopefully also include the CSS style info and any other necessary/helpful parts of the page to freeze frame.
- Something along the lines of
WebDriverCurrentStateSnapshot snapshot = driver.getCurrentPageStateSnapshot() snapshot.findElement(By.id("somebutton").isDisplayed();
This snapshot object wouldn't be graphical, it wouldn't even be "headless". There'd be no browser/driver involved, it would be purely a state capture object (probably immutable) with a subset of the driver's API. This is sort of like a network requests HAR file, but would be the entire page state instead of network requests (may include network requests?)
This (immutable?) WebDriverCurrentStateSnapshot object would have a subset of driver functionality:
- The snapshot object would be able to immutable-safe and idempotent operations
snapshot.findElementand return aWebElement(SnapshotWebElement?)- Checks and queries for values and against WebElements, such as:
element.getText(),element.getAttribute(),element.getPosition(), etc...
- The Snapshot wouldn't be able to do Actions or anything with side-effects
- It couldn't interact or click, because it's a snapshot in time, not live
- Or could it? If it's a link to some URL, wouldn't this be possible to pick up in the original driver by following the link? 🤷♂️ I'm not sure about this part
- It couldn't interact or click, because it's a snapshot in time, not live
Possible Issues
I'm not sure what the contents of the snapshot object would entail.
- At the very least, the snapshot would have the DOM.
- Then, after that, we'd want the CSS style and page layout too, or some way to emulate that so we can check element positioning.
- I'm not sure if Selenium can correctly grab the CSS/layout (I know Selenium has a hard time getting CSS pseudo-classes)?
- After that, would the snapshot also have a HAR file as part of it as well?
- Other things that I haven't listed?
Would it be possible to grab everything needed just from the driver? Is there anything the driver can't get from the browser that would block the making of a useful snapshot?
Would the snapshot need some emulator or to implement it's own layout engine to support the driver operations?
Would this page snapshot simply be too big to transfer to the user through the Selenium server? Would the use be okay with that size tradeoff and handle the bandwidth/memory issues on the client side?
Motivation
- All checks made against a page snapshot would happen at "a single point in time", not as sequential commands over a period of time
- No StaleElementReferenceExceptions would occur at all for any rid of StaleElementReferenceExceptions during the course of certain checks
- Since this would probably be an immutable object, it can allow thread safety/parallel operations
Example
- Johnny wants to check a bunch of elements on the page for a certain condition (e.g. that they are all displayed)
- Johnny calls
Arrays.stream(driver.findElements(By.xpath("//*"))).forEach( element -> element.checkSomething()) - The page is constantly changing (due to the way it's designed: flashing lights, elements coming in and out), so Johnny is getting StaleElementReferenceExceptions.
- Johnny doesn't know how to deal with these StaleElementReferenceExceptions apart from start over or ignore them. It's not possible to retarget the same element once it went stale without just re-finding all of them.
Insert a step in between 1 and 2 to get a WebDriverCurrentStateSnapshot, where we'll run all the checks against the snapshot instead of the driver. This will get rid of the StaleElementReferenceExceptions.
- Johnny wants to check a bunch of elements on the page for a certain condition (e.g. that they are all displayed)
- Johnny gets a snapshot of the current page with
WebDriverCurrentStateSnapshot snapshot = driver.getCurrentPageStateSnapshot() - Against the snapshot, Johnny calls
Arrays.stream(snapshot.findElements(By.xpath("//*"))).forEach( element -> element.checkSomething()) - Even if the actual browser page is constantly changing, the snapshot is an immutable, frozen point in time. Johnny gets no StaleElementReferenceExceptions and completes his checks.
This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 14 days.
This issue was closed because it has been stalled for 14 days with no activity.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.