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,230 points
519 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,150 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 13 in Selenium by Surya
• 970 points
175 views
0 votes
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,110 points
2,413 views
0 votes
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,110 points

edited Apr 4, 2018 by nsv999 3,447 views
0 votes
1 answer
0 votes
1 answer

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,110 points
1,150 views
0 votes
1 answer
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,150 points
1,248 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,150 points
1,005 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,150 points
54 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,150 points
1,951 views