How to use POM in Selenium (Simple Login Test Case)

How to use Page Object Model in Selenium by using WebDriver. First of all, make one class where we create our page object which we call later from main class.

Step 1 : Make Class with Objects

import org.openqa.selenium.By;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class pom_wo_pf { By username=By.id(“email”);
By password=By.id(“pass”);
public WebDriver driver;
public void POM_FB (WebDriver driver) throws InterruptedException
{
driver.findElement(username).click(); driver.findElement(username).sendKeys(“test_test@yahoo.com”); driver.findElement(password).click(); driver.findElement(password).sendKeys(“Password”); if(driver.findElements(By.id(“u_0_5”)).size() != 0)
{
System.out.println(“Element is Present”);
driver.findElement(By.id(“u_0_5”)).click();
}
else if(driver.findElements(By.id(“u_0_2”)).size() != 0)
{
System.out.println(“Element is Absent”);
driver.findElement(By.id(“u_0_2”)).click();
}
else {
System.out.println(“Element is Absent 02”);
}
}
}

Step 2: Now Create main class and call your child class

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class pom_use
{
static WebDriver driver;
public static void main(String[] args) throws InterruptedException
{
driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get(“https://www.facebook.com/”);
pom_wo_pf pom_fb_check = new pom_wo_pf(); pom_fb_check.POM_FB(driver);
}
}

How to use POM in Selenium (Simple Login Test Case)

14 thoughts on “How to use POM in Selenium (Simple Login Test Case)”

  1. This article offers a fascinating perspective on the subject. The depth of research and clarity in presentation make it a valuable read for anyone interested in this topic. It’s refreshing to see such well-articulated insights that not only inform but also provoke thoughtful discussion. I particularly appreciated the way the author connected various aspects to provide a comprehensive understanding. It’s clear that a lot of effort went into compiling this piece, and it certainly pays off. Looking forward to reading more from this author and hearing other readers’ thoughts. Keep up the excellent work!

  2. Fantastic article! I appreciate how clearly you explained the topic. Your insights are both informative and thought-provoking. I’m curious about your thoughts on the future implications of this. How do you see this evolving over time? Looking forward to more discussions and perspectives from others. Thanks for sharing!

  3. Great article! I found your perspective on this topic both enlightening and thought-provoking. The way you break down complex ideas into understandable insights is truly commendable. It’s interesting to see how these developments could shape our future. I’m particularly intrigued by your point about potential challenges and would love to dive deeper into that.

    For those who are interested in exploring this topic further, I recommend checking out this resource for more detailed information: comprehensive guide. It offers additional insights that complement what’s discussed here.

    Looking forward to hearing others’ thoughts and continuing this discussion. Thanks for sharing such valuable information!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top