I am initializing a variable in the beginning of my class:
public WebElement logout; Later on in the code, in some method, the first time I encounter the logout button, I assign a value to that variable (in the brackets of an if/else statement):
logout = driver.findElement(By.linkText("Logout")); logout.click(); I then use "logout" once more, successfully, at another stage of my test:
logout.click(); And at the end of the test, at a place where the element is the same (By.linkText ("Logout")), I get this error:
Element not found in the cache - perhaps the page has changed since it was looked up Why?
EDIT: Actually, I dont successfully use the logout.click(); commant at another stage of my test. Looks like I cant use it again. I have to create a logout1 webelement and use it...
findthe element again before trying to click it at the stage it would normally break? An idea, why not create alogoutmethod that finds and clicks the element each time it is required?