Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

WebElement refresh() or getBy() needed #4419

Closed
lukeis opened this issue Mar 4, 2016 · 6 comments
Closed

WebElement refresh() or getBy() needed #4419

lukeis opened this issue Mar 4, 2016 · 6 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 4, 2016

Originally reported on Google Code with ID 4419

What steps will reproduce the problem?
1. Build an iterator to step through a WebElement List:

List<WebElement> elements = driver.findElements(by);

for(WebElement localElement: elements){

localElement = driver.findElements(By.xpath(xpath)).get(rec).findElements(By.cssSelector("[class*=filterButton]");

if (localElement.getAttribute("innerHTML").contains(">" + groupName + "<")){

localElement.click();  //This causes a page refresh.
}...

//localElement is stale. Needed here: 
localElement.refresh(); //or

//refresh itself where getBy() is not currently accessible:
localElement = findElement(localElement.getBy());

2. Try to perform any command on localElement which is performed after the page refresh.
At this point after the click, the localElement is stale, and you cannot access it
again unless you perform a whole new routine to locate it again. In my test app, the
foundBy is many times identical to what it was before the click.

What is the expected output? What do you see instead?

I expect WebDriver to have an element.refresh() method or element.getBy() method so
WebElements can easily be reused.

The element is stale, which is fine.  But what is missing from Selenium is a feature
such as WebElement.refresh() to de-stale the element.  

Selenium version: 2.25.0
OS: Windows 7
Browser: Firefox
Browser version: 14.0.1


Reported by jdmptest on 2012-08-14 18:26:05

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

WebElement object is a proxy, a representative of a DOM element. When DOM element is
destroyed by the browser, WebElement is marked "stale" and can't be used anymore.

If you have a *similar* DOM element on another page, you can obtain it with findElement,
and Selenium will create a *new* WebElement object (a proxy) for this *new* DOM element.
Your old WebElement object will remain stale because underlaying DOM object is destroyed
and never can be restored. Similarity is not equality.

Reported by barancev on 2012-08-14 20:26:20

  • Status changed: WorkingAsIntended
  • Labels added: Component-WebDriver
  • Labels removed: Status-Untriaged

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

So what is the solution for building something like the getter for the By property in
the WebElement so it can be reused later?  I have instances where the web page is refreshed
by the server due to a click but the refreshed page is practically a clone of what
it was previous to the click.  Seems nuts to throw the identifier logic into  private
routines throughout my framework, when something like a getBy() supported by the entire
framework would be logical.  (Also I am doing my best not to look back at QuickTest
Professional, and this is one thing QTP can do is refresh tables etc.  I know this
isn't Qtp!)

Reported by jdmptest on 2012-09-11 15:17:19

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I know this is a since long closed Issue, but a built in function for finding a changed
but identical DOM-object like suggested above, or even just storing the By-object in
the WebElement for later reuse is a verry good feature.

Reported by fredrik.svensson@fortnox.se on 2013-10-24 14:12:48

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

WebElements should have references to their By. That would solve most of the issues
related to "refresh" as it would be very easy to recreate the webelement if needed.
Its just good practice for OOO to unfortunately cache your webelements to be used later
in the function. Sometimes, this can cause webelements to be .

It makes no sense to me why WebElements don't know about how they are found. I don't
want to "re-write the wheel" just so I can get access to the original By selector.
This would solve so many stale element bugs on a testers end its ridiculous its not
included.

Reported by jason.smiley@1stdibs.com on 2014-05-02 20:42:24

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I wonder if refreshing the proxy's remote element is futile, even though it may be possible
to implement.  The caller of the refresh method will not get and operate on an atomic
snapshot of the page if the page mutates.  It would be fun to use an atomic page snapshot.
 A browser's javascript engine would need a mode of operation where it (a) forks into
a temporary snapshot, (b) keeps processing events but (c) cannot mutate DOM.

I stumbled on this ticket only because I was looking for something like WebElement.refresh()
or WebElement.getBy() to materialize and pass an annotated webelement to JavascriptExecutor#executeScript()
as a WebElelement argument.  It seems JavascriptExecutor cannot handle a WebElement
proxy in Safari.

Reported by eelgheez on 2015-07-14 03:27:03

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by luke.semerau on 2015-09-17 18:16:01

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 4, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant