RE: Advise on locating elements when there is a page refresh that happens

Hi ,

Am trying to automate JIRA application create_issue .When create button is clicked , there is page which gets displayed that allows us to select project,issue_type, summary etc and then finally submit .

I observe that when we select a project in the project field and press enter, the page gets refreshed . Now i try to locate the next element which is issue_type but get the below error.

Clicked on create_link
Project Selected
Exception in thread “main” org.openqa.selenium.StaleElementReferenceException: Element not found in the cache – perhaps the page has changed since it was looked up
Command duration or timeout: 10.05 seconds

Could you please help identify what could be the issue ?


Below is the JAVA code

System.out.println(“Clicked on create_link”);
WebElement project = driver.findElement(By.xpath(“.//*[@id=’project-field’]”));;
project.sendKeys(“A Test Project”);
System.out.println(“Project Selected”);

WebElement issue = driver.findElement(By.xpath(“.//input[@id=’issuetype-field’]”));

Asha Default Asked on November 21, 2014 in Selenium WebDriver.
Add Comment
3 Answers

Hi Asha,

I am sure you must be following the Page Factory pattern and in that it is a very common issue. After every page refresh, you need to instantiated Page elements again to use it again. You may be using @CacheLookup, if yes please avoid it.

You may like to follow my Page Object Model designed by me using plain Java concept to avoid these situations.

Lakshay Sharma

Professor Answered on November 24, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.