1

I am automating a website using POM framework and I have one page class and a test class (out of many).

The page class is : FindPeople.java and the code I have written inside is like below:

public class FindPeople {

    @FindBy(id="ContentPlaceHolderDefault_Body_Body_Content_***SearchSimpleDialog_13_tbQuery")

    WebElement serachfield;

    @FindBy(xpath=".//*[@id='ContentPlaceHolderDefault_Body_Body_Content_***SearchSimpleResults_14_pnlResults']/div[1]/div/a")

    WebElement serachresult;

    public void typeInSearchField()
    {
        serachfield.sendKeys(DataProviderFactory.readHomeData().getPeopledata(2, 0));
    }
}

I have test class called VerifyInputField.java and code inside is like below:

public class VerifyInputField {

    WebDriver driver;

    @Test
    public void verifyInputField() throws AWTException {

        driver= BrowserFactory.getBrowser("Chrome");

        BrowserFactory.getURL();

        FindPeople findpeople = PageFactory.initElements(driver, FindPeople.class);

        findpeople.typeInSearchField();
     }
}

The problem is, the Webelemnts (serachfield, serachresult) I identified in FindPeople.java; are not accessible in VerifyInputField.java. I mean, I am not getting the usual methods like click(), gettext() using any of these elements.

Am I doing anything wrong?

tim-slifer
  • 1,068
  • 1
  • 9
  • 17
Prabodh Ghosh
  • 161
  • 2
  • 17

2 Answers2

0

The properties serachfield and serachresult seems like package private to which are not accessible from outside of the package. All you need to do is make them public with public access modifier.

And, speaking about the best practices of POM, you should not access those properties publicly anyway. Try creating methods inside FindPeople class which will help you to use those properties and make the methods public

Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Even after making them public; they are not accessible. So I think it has got something to do with @FindBy or PageFactory class or both. I have created a method to access these elements. However, it is really feasible to create method to perform every action surrounding a Webelement? Because, we might want to perform so many actions using an element (1. Click 2. Sendkeys 3. MoveToElement... to name a few) which are provided in Webdriver API. If we need to create methods again, first, maintenance will be hectic, second, we are doing redundant task. What is your thought on this? – Prabodh Ghosh Dec 09 '15 at 18:26
0

Every property which is declared without access modifier is private, so you have to specify it exactly, if you want to create public property. But I agree with Saifur about best practices and creating inside method for access to properties.

May be some useful info here: https://stackoverflow.com/a/215505/2131257.

Community
  • 1
  • 1
Androdos
  • 653
  • 8
  • 11
  • Without access modifier is not Private, rather Default. Do you mean Package Private? – Prabodh Ghosh Dec 09 '15 at 18:27
  • Yes, sorry for mistake :-) I meant package private. But as you commented in previous comment, that public modifier doesn't help, it doesn't matter :-D – Androdos Dec 11 '15 at 06:04