I understood the issue. All the fields and methods should be in a
separate class or, even in the same class, the method should be a
different one.
This static method (PageFactory.initElements) always returns the
initialized class's object. With this object only we have to achieve
the task.
---- this code should be in another class ----------- E.g. TestClass2
temp1 tco= PageFactory.initElements(driver, temp1.class);
temp1.searchAll("test text");
------------------------------------------------
public class temp1 {
@FindBy(name="p")
public WebElement searchBox;
public void searchAll(String te)throws Exception
{
searchBox.sendKeys(te);