英文:
selenium script to check the placeholder value of the Lastname textbox
问题
Getting error: Could not find or load main class PageLocator.
Please check if methods are fine and if I am calling the methods correctly in the main class
我在需要测试字段的占位符
public class PageLocator //不要更改类名
{
static WebDriver driver;
static WebElement LN;
public WebDriver createDriver() //不要更改方法签名
{
    DriverSetup ds = new DriverSetup();
    driver = ds.getWebDriver();
    return driver;
}
public WebElement getPageLocator(WebDriver driver) //不要更改方法签名
{
    /*Replace this comment by () code statement to get the WebElement of 'Lastname'*/
    /*Find the element by id */
    LN = driver.findElement(By.id("lastname"));
    return LN;
}
public String getName(WebElement element) //不要更改方法签名
{
    //Get the attribute value from the element and return it
    getPageLocator pll = new getPageLocator(element);
    String LastN = pll.getAttribute("placeholder");
    return LastN;
}
public static void main(String[] args){
    PageLocator pl=new PageLocator();
    WebElement LN = pl.getPageLocator(driver);
    String name=pl.getName(LN);
    System.out.println("The Lastname is "+name);
}
}
英文:
Getting error: Could not find or load main class PageLocator.
Please check if methods are fine and if i am calling the methods correctly in main class
I am in need to test the placeholders of the fields
public class PageLocator    //DO NOT Change the class Name
    {
	
	 static  WebDriver driver;
	 static   WebElement LN ;
	
	public WebDriver createDriver()  //DO NOT change the method signature
	{
	        
	       
	        DriverSetup ds = new DriverSetup();
            driver =  ds.getWebDriver();
            return driver;
	}
	
	public WebElement getPageLocator(WebDriver driver)  //DO NOT change the method signature
	{
	   /*Replace this comment by () code statement to get the WebElement of 'Lastname'*/
	   /*Find the element by id */
	   
	   LN = driver.findElement(By.id("lastname"));
	   
	   return LN;
    
	}
	public String getName(WebElement element)  //DO NOT change the method signature
	{
	    //Get the attribute value from the element and return it
	   
	   getPageLocator pll = new getPageLocator(element);
	    String LastN = pll.getAttribute("placeholder");
	    return LastN;
	}
	
	public static void main(String[] args){
	    
	    PageLocator pl=new PageLocator();
	    WebElement LN = pl.getPageLocator(driver);
	    String name=pl.getName(LN);
        System.out.println("The Lastname is "+name);
	}
答案1
得分: 1
你需要在 main 方法中调用 createDriver() 方法。因此,你的 main 方法应该如下所示:
public static void main(String[] args){
    PageLocator pl = new PageLocator();
    WebDriver driver = pl.createDriver();
    WebElement LN = pl.getPageLocator(driver);
    String name = pl.getName(LN);
    System.out.println("The Lastname is " + name);
}
英文:
You need to call the createDriver() method in the main method.
So your main method should look like this:
public static void main(String[] args){
    PageLocator pl=new PageLocator();
    WebDriver driver = pl.createDriver();
    WebElement LN = pl.getPageLocator(driver);
    String name=pl.getName(LN);
    System.out.println("The Lastname is "+name);
}
答案2
得分: 0
您的 getName 方法应该是:
public String getName(WebElement element)
{
    String LastN = LN.getAttribute("placeholder");
    return LastN;
}
英文:
Your getName method should be
public String getName(WebElement element)
{
    String LastN=LN.getAttribute("placeholder");
    return LastN;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论