selenium脚本以检查姓氏文本框的占位符值

huangapple go评论142阅读模式
英文:

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;
}

huangapple
  • 本文由 发表于 2020年8月14日 14:36:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63407724.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定