0

I am a complete newbie in Selenium and java in general. I am trying to use the Page object model with Page factory to create Page object class for the Login page of an application. When I create a method the WebElement object errors indicating the follwoing: error message . I have seen other demonstrations where the webelements do not have to be static. I don't know what I can be doing wrong.

package com.imis.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import Actiondriver.ImisActionclass;
import Base.basepackage;

public class login extends basepackage {
    
    @FindBy(xpath="//input[@id='ctl01_TemplateBody_WebPartManager1_gwpciSignIn_ciSignIn_signInUserName']")
     WebElement userName;
    
    @FindBy(xpath="//input[@id='ctl01_TemplateBody_WebPartManager1_gwpciSignIn_ciSignIn_signInPassword']")
     WebElement password;
    
    @FindBy(xpath="//input[@id='ctl01_TemplateBody_WebPartManager1_gwpciSignIn_ciSignIn_SubmitButton']")
     WebElement submitButton;

    public login() {
        PageFactory.initElements(driver, this);
        }
    
    public static void loginpage(String uname, String pswd) {
        ImisActionclass.type(userName, text);
        ImisActionclass.type(pswd, password);
        ImisActionclass.click(driver, submitButton);
    
  • Declare userName as static... – Gi1ber7 Oct 26 '20 at 17:55
  • @Gi1ber7 but does the keyword "static" always need to be defined in WebElements objects? why cant it remain as "WebElement userName;" – Juan Pereyra Oct 26 '20 at 23:38
  • userName has to be defined static because is used on the static module loginpage. If loginpage wasn't static, then userName doesn't need to be either. – Gi1ber7 Oct 27 '20 at 00:44
  • Here is a better explanation: https://stackoverflow.com/questions/413898/what-does-the-static-keyword-do-in-a-class?noredirect=1&lq=1 – Gi1ber7 Oct 27 '20 at 00:52
  • 1
    @Gi1ber7 removing static from the loginpage function did the trick. Thank you! – Juan Pereyra Oct 27 '20 at 16:08

0 Answers0