0 Replies Latest reply on Feb 28, 2014 9:00 AM by Petr Mensik

    Page object in Graphene complains about non-present elements

    Petr Mensik Newbie

      Hello,

       

      I would like to have HomePage class which will hold different WebElement attributes annotated by @FindBy. Problem is that number of elements on my home page can change depending on whether is user logged in or not and I am keep getting NoSuchElement on the elements which are currently not present. I am getting this exception even without @FindBy - see the following example, Drone executes first line of test just fine (i.e. user successfully logs in and he is returned to the homepage) but than I get exception about missing element with class="Login" which is mentioned only in method openAndGetLoginForm.

       

      public class TestChangeLanguage extends AbstractWebDriverTest<HomePage> {
      
          @FindBy(className = "UIChangeLanguageForm")
          private ChangeLanguageForm languageForm;
         
          @Test
          public void testLanguage() throws InterruptedException {
              page.openAndGetLoginForm().signAsRoot(); //this executes fine
              languageForm.changeLanguage("language.french"); //here I get the exception about missing element
          }
      }
      

       

      public class HomePage implements AbstractPage {
      
          @Drone
          private WebDriver driver;
         
          @FindBy(id = "UIPortalComponentLogin")
          private LoginForm loginForm;
         
          public LoginForm openAndGetLoginForm() {
              driver.findElement(By.className("Login")).click();//here is where WebDriver complains about missing element after I log in through LoginForm (logging in works fine)
              return loginForm;
          }
      }
      

       

      And the exception is Unable to locate element: {"method":"class name","selector":"Login"}. So is it even possible to have Page Object which can have defined WebElements which are not always present on the page (and of course test code won't refer to these objects when they are not present)?And how do I work around the situation in my example, I am referring to Login link only inside the method but yet I get exception about missing element even after the method is executed.