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 ?

Thanks

Below is the JAVA code
————————-

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

wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(“//div[@id=’issuetype-single-select’]”)));
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.
http://www.toolsqa.com/selenium-webdriver/page-object-model/

Regards,
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.