SELECT statement in POM-TestNG classes in java selenium

0 votes

How to write Select Statement in POM Class. Other TestNG class is calling that POM Class

Below is POM code:

package POM;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.FindBy;

import org.openqa.selenium.support.PageFactory;

import org.openqa.selenium.support.ui.Select;

public class LoginCRM {

    @FindBy(id="ctl00_ContentPlaceHolder1_PassiveIdentityProvidersDropDownList")

    private WebElement dropdown;


    @FindBy(id="ctl00_ContentPlaceHolder1_PassiveSignInButton")

    private WebElement sltbtn;


    @FindBy(id="ctl00_ContentPlaceHolder1_UsernameTextBox")

    private WebElement usrname;


    @FindBy(id="ctl00_ContentPlaceHolder1_PasswordTextBox")

    private WebElement password;


    @FindBy(id="ctl00_ContentPlaceHolder1_SubmitButton")

    private WebElement login_btn;


    public LoginCRM(WebDriver driver) {

        PageFactory.initElements(driver, this);

        // TODO Auto-generated constructor stub

    }


    public void login()

    {

        Select sel = new  Select(dropdown);

        sel.selectByVisibleText("HP Internal STS");


        sltbtn.click();

        usrname.sendKeys("r@gmail.com");

        password.sendKeys("@@@@@@@");

        login_btn.click();

    }


}

NullPointerException at select statement of login method 

 @Test

  public void login() {

      LoginCRM log = new LoginCRM(driver);

      log.login();

  }

Below is HTML code

<form id="aspnetForm" action="/adfs/ls/?wa=wsignin1.0&wtrealm=https%3a%2f%2fppmss360.ford.qa.ams.hpmsdynamics.com%2f&wctx=rm%3d1%26id%3dd05e86a7-ae60-4d86-af91-c70fe89fb627%26ru%3dhttps%253a%252f%252fppmss360.ford.qa.ams.hpmsdynamics.com%252fdefault.aspx&wct=2015-12-15T16%3a42%3a34Z&wauth=urn%3aoasis%3anames%3atc%3aSAML%3a1.0%3aam%3apassword" method="post" name="aspnetForm">

<div>

<div>

<input type="hidden" value="14" name="__db"/>

<div class="MainArea">

<div class="Header">

<div class="GroupXLargeMargin">

<div class="GroupLargeMargin">

<div class="MainActionContainer">

<div class="GroupXLargeMargin">

<div class="GroupXXLargeMargin">

<select id="ctl00_ContentPlaceHolder1_PassiveIdentityProvidersDropDownList" name="ctl00$ContentPlaceHolder1$PassiveIdentityProvidersDropDownList">

<option value="http://corp.sts.ford.com/adfs/services/trust">Ford Corp STS</option>

<option value="https://mscrm00b.hpuscrmpoc.com/adfs/services/trust">HP Internal STS</option>

</select>

<div>

</div>

</div>

Below is the exception printed

[TestNG] Running:

  C:\Selenium Workspace\FMC360Automation\testng.xml


java.lang.NullPointerException

    at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)

    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)

    at com.sun.proxy.$Proxy6.getTagName(Unknown Source)

    at org.openqa.selenium.support.ui.Select.<init>(Select.java:44)

    at POM.LoginCRM.login(LoginCRM.java:34)

    at Script.LoginMain.login(LoginMain.java:15)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)

    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)

    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)

    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)

May 24, 2018 in Selenium by Martin
• 4,320 points
4,345 views

1 answer to this question.

0 votes

Initialize the WebDriver driver and add @BeforeTest method in your TestNG class.

public class WebDriverTest  {       

    WebDriver driver;

    @BeforeTest

     public void setup(){

        driver = new FirefoxDriver();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        driver.get("file:///C:/Users/dummyUser/Desktop/select_page.html");

    }

@Test

public void testLogin()

{

     LoginCRM log = new LoginCRM(driver);

     log.login();

    }

}
answered May 24, 2018 by Samarpit
• 5,910 points

Related Questions In Selenium

0 votes
1 answer

How to get the select options using Selenium WebDriver in Java

Hey there! You should be able to get ...READ MORE

answered Jun 14, 2019 in Selenium by Surya
• 970 points
4,683 views
+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13, 2020 in Selenium by Karan
• 19,610 points
8,187 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,233 views
+1 vote
1 answer

How to perform mouse hovering in Selenium WebDriver (Java)?

You many not actually be able to ...READ MORE

answered Apr 3, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 22, 2023 by Khan Sarfaraz 10,667 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,420 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,995 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,101 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,800 views
0 votes
1 answer

Contains expression in Selenium using Java Language

Do something like this: WebElement thingie = driver.findElement(By.xpath("//tr[contains(@id,'" ...READ MORE

answered May 4, 2018 in Selenium by Samarpit
• 5,910 points
819 views
0 votes
1 answer

How to eliminate this error”Cannot instantiate the type Select in selenium webdriver”

Try below code. Select sc = new Select(driver.findElement(By.xpath("your ...READ MORE

answered May 18, 2018 in Selenium by Samarpit
• 5,910 points
9,892 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP