java - JUnit 4 (WebDriver) on Ubuntu -


i use junit 4 , selenium webdriver , eclipse run test on ubuntu.
when run test have error:

> org.openqa.selenium.staleelementreferenceexception: element not found > in cache - perhaps page has changed since looked 

and when debug test works.
, test:

package com.qd2.login;  import java.util.concurrent.timeunit;    import org.junit.*;    import static org.junit.assert.*;    import org.openqa.selenium.*;   import org.openqa.selenium.firefox.firefoxdriver;  public class login {        private webdriver driver;       private string baseurl;       private stringbuffer verificationerrors = new stringbuffer();    @before   public void setup() throws exception {     driver = new firefoxdriver();     baseurl = "http://localhost:8088/";     driver.manage().timeouts().implicitlywait(30, timeunit.seconds);      }     @test   public void testuntitled() throws exception {     driver.get(baseurl + "/qd2/pages/accueil/login.xhtml#loaded");     //driver.findelement(by.id("login")).clear();     driver.findelement(by.xpath("//*[@id='login']")).sendkeys("admin");     //driver.findelement(by.id("password")).clear();     driver.findelement(by.id("password")).sendkeys("admin");     driver.findelement(by.id("loginbutton")).click();      }    @after   public void teardown() throws exception {     //driver.quit();     string verificationerrorstring = verificationerrors.tostring();     if (!"".equals(verificationerrorstring)) {       fail(verificationerrorstring);     }      } } 

this exemple of : org.openqa.selenium.staleelementreferenceexception

webelement element = driver.findelement(by.id("input123")); // input  webelement button= driver.findelement(by.id("btn123")); // button sends form button.click(); element.sendkeys("the cache released.."); // error here 

so think come #loaded that's inside url

driver.get(baseurl + "/qd2/pages/accueil/login.xhtml#loaded"); 

try without , tell me what's up.


update :

try use wait :

[...] webelement login = (new webdriverwait(driver, 10))               .until(expectedconditions.presenceofelementlocated(by.id("login"))); login.sendkeys("admin"); [...] 

but normally wait not since error happens when you're have changed source naviguate page or sent form etc..


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -