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)