List <WebElement> with Page object Model

1,265 views
Skip to first unread message

sonia...@gmail.com

unread,
Dec 22, 2014, 4:22:55 AM12/22/14
to webd...@googlegroups.com
Hi Guys,

I have below if condition to check if a particular error message exists on screen and on the basis of this error my script proceed with correct login credentials. I just started using POM for my scripts.

My POM class:

public static WebElement assert_Login(WebDriver error){
                 
                 List<WebElement> error = error.findElements(By.xpath("abcError"));
               
                 element = (WebElement) error;
         
                 return element;


Test case Class:
public class Login
{
private static WebDriver driver = null;
private static String error = null;


    @BeforeTest
     
    public void setBaseURL()
        {
            driver = new FirefoxDriver();
           
        }
     
    @Test(dataProvider = "iteratorTestData1")
      public void project(String baseurl, String username, String password){

        driver.get(baseurl);
        driver.manage().window().maximize();

 if(LoginPage.assert_Login(!error.isEmpty()))
         {
                System.out.println("Username Or Password is Incorrect" + username);
               
               Assert.fail("Username Or Password is Incorrect" + error.get(0).getText());
            }
     
         System.out.println(" Login Successfully!!");
}

Error that eclipse shows in test case class:

1. The method get(int) is undefined for the type String
2. The method assert_Login(WebDriver) in the type LoginPage is not applicable for the arguments (boolean)

Please correct my code as I dont have much knowledge of programming. Also, please suggest me some good beginners tutorials for POM with selenium webdriver.

Thanks in advance!

Mrunal Gosar

unread,
Dec 27, 2014, 12:55:44 PM12/27/14
to webd...@googlegroups.com
You need to first learn Java (Basic). If not, then selenium is available in many other programming language bindings. you can choose the language which you are comfortable with.
As far as errors are concerned:
1. static variable "error" is declared as String and it does not have a get method.
2. assert_login method accepts an object of type WeDriver and you are passing and object of type boolean. so that won't work.

A quick search on google for page objec model in selenium returned below results:


You can look for other tutorials too.

Selenium Framework

unread,
Jan 2, 2015, 10:33:55 AM1/2/15
to webd...@googlegroups.com
If you are new to Selenium, you would have to make a choice of programming language and I'd suggest if you are new to programming , ruby with selenium is relatively easier and less verbose than Java. Page Object model is available in pretty much in Ruby, Groovy,Java, C# etc

Entire tutorial with real time project is here - http://www.seleniumframework.com/hybrid-framework/what-is-page-object/
Reply all
Reply to author
Forward
0 new messages