kubo
kubo

Reputation: 13

How can'i clear the cache WebElement list in Selenium?

can anyone help me please, it is possible in Java to clear the cache elements located by Selenium every execution?

I'm testing an application which do not have access to the HTML code and whose components have not fixed ID (are dynamic), so I need to recover the elements through its content, not only that, the url of the application does not change, because the components are generated via ajax / jQuery.

So when using a xPath that has already been used on another occasion, the selenium does not perform a new search and always returns the same element.

Below the xpath I use to locate the Enter button on a page:

 WebElement findElement = driver.findElement(By.xpath("//button[contains(.,'Entrar')]"));

If you use the X page and repeat the same path on page Y, always get the page element X. How do I clear the cache?

Upvotes: 1

Views: 2067

Answers (2)

Vaish
Vaish

Reputation: 56

Is there any exception thrown saying element could not be found. May be in your case element in page y could not be located by webdriver and so the previous element still remains.

Upvotes: 1

StrikerVillain
StrikerVillain

Reputation: 3776

You just have to call the code to find element each time you want to use that element.

findElement = driver.findElement(By.xpath("//button[contains(.,'Entrar')]"));

So each time you use the element, the new element in the Page is found.

Upvotes: 0

Related Questions