Selenium WebDriver NullPointerException while grabbing url - java

I have found multiple answers to this issue but none that seem to help me here. When ever i run my test, I get a NullPointerException. I image it is a simple fix but I can't find it.
Here is my set up class:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.fail;
public class TestSetUp {
private WebDriver driver;
protected StringBuffer verificationErrors = new StringBuffer();
public WebDriver getDriver() {
return driver;
}
private void setDriver(String type, String url) {
switch (type) {
case Config.FIREFOX_DRIVER:
System.out.println("Setting drivers for Firefox...");
driver = initFireFoxDriver(url);
break;
default:
System.out.print("invalid browser type");
}
}
private static WebDriver initFireFoxDriver(String url) {
System.out.println("Launching Firefox browser...");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.navigate().to(url);
return driver;
}
#BeforeClass
#Parameters({"type","url"})
public void initializeTestBaseSetup(String type, String url) {
try {
setDriver(type, url);
} catch (Exception e) {
System.out.println("Error....." + Arrays.toString(e.getStackTrace()));
}
}
#AfterClass
public void tearDown() {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
This is my LoginPage class where the error is being thrown:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class LoginPage {
private WebDriver driver;
public LoginPage(WebDriver driver) {
this.driver = driver;
}
private String getLoginTitle() {
return driver.getTitle();
}
public boolean verifyURL() {
return driver.getCurrentUrl().contains("login");
}
public boolean verifyLoginTitle() {
return getLoginTitle().contains(Config.TITLE + " - Log In");
}
public boolean verifySignInError() {
enterUsername("test");
enterPassword("pass");
clickLogin();
return getErrorMessage().contains("Incorrect Username or Password");
}
public boolean verifyForgotPassword() {
return driver.findElement(Config.FORGOT_PASS_NODE).isDisplayed();
}
public boolean verifyLicencing() {
Config.changeSetting("multi_license", 1, driver);
return driver.findElement(Config.LIC_KEY_NODE).isDisplayed();
}
public boolean verifyCreateAccount() {
Config.changeSetting("user_reg", 0, driver);
if(driver.findElement(Config.CREATE_ACCOUNT_NODE).isDisplayed()) {
return false;
}
else {
Config.changeSetting("user_reg", 1, driver);
}
return driver.findElement(Config.CREATE_ACCOUNT_NODE).isDisplayed();
}
public HomePage signIn(String username, String password) {
enterUsername(username);
enterPassword(password);
clickLogin();
return new HomePage(driver);
}
public void enterUsername(String username) {
WebElement identity = driver.findElement(Config.IDENTITY_NODE);
if(identity.isDisplayed())
identity.sendKeys(username);
}
public void enterPassword(String password) {
WebElement pass = driver.findElement(Config.CREDENTIAL_NODE);
if(pass.isDisplayed())
pass.sendKeys(password);
}
public void clickLogin() {
WebElement loginBtn = driver.findElement(Config.SUBMIT_NODE);
if(loginBtn.isDisplayed())
loginBtn.click();
}
public String getErrorMessage() {
String errorMessage = null;
WebElement errorMsg = driver.findElement(Config.DANGER_NODE);
if(errorMsg.isDisplayed())
errorMessage = errorMsg.getText();
return errorMessage;
}
}
And finally my test case:
import org.junit.Assert;
import org.junit.Before;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
public class LoginPageTest extends TestSetUp {
private WebDriver driver;
#Before
public void setUp() {
driver = getDriver();
}
#Test
public void verifyLoginInFunction() {
System.out.println("Log In functionality being tested...");
LoginPage loginPage = new LoginPage(driver);
try {
Assert.assertTrue("The url is incorrect", loginPage.verifyURL());
} catch (Error e) {
verificationErrors.append(e.toString());
}
try {
Assert.assertTrue("Title did not match", loginPage.verifyLoginTitle());
} catch (Error e) {
verificationErrors.append(e.toString());
}
try {
Assert.assertTrue("Error message did not match", loginPage.verifySignInError());
} catch (Error e) {
verificationErrors.append(e.toString());
}
try {
Assert.assertTrue("\'Forgot Password?\' link is missing", loginPage.verifyForgotPassword());
} catch (Error e) {
verificationErrors.append(e.toString());
}
try {
Assert.assertTrue("Create Account setting not working", loginPage.verifyCreateAccount());
} catch (Error e) {
verificationErrors.append(e.toString());
}
try {
Assert.assertTrue("Additional Licence Key setting not working", loginPage.verifyLicencing());
} catch (Error e) {
verificationErrors.append(e.toString());
}
HomePage homePage = loginPage.signIn(Config.STUDENT, Config.STUDENTPASS);
try {
Assert.assertTrue("Login did not work", homePage.verifyURL());
} catch (Error e) {
verificationErrors.append(e.toString());
}
}
}
I have been trying and just do not know what is causing the issue.

So, I was just dealing with this same problem and realized this question was asked about 7 years ago. I thought I would share what I have come up with as my solution.
For the instance you are trying to access you are passing a null. You assign a value to something that hasn't been initialized yet which gives you the exception you are seeing :) a null value into the driver loginPage is a no no. First initialize -> then pass value -> happy outputs.
I'm not here to give you a coding lesson as you have proven to show you know what you are doing, but happy coding!

Related

java.lang.NullPointerException in PageObjectModel Project

I have two pages, in one everything is fine, but in the other I get java.lang.NullPointerException
What is my mistake? Please help
LoginPage.java - all good
package page;
import Base.Base;;
import paths.LoginPath;
public class LoginPage extends Base {
LoginPath loginPath = new LoginPath();
public void ingresarPagina(){
chromeDriverConnection();
visit(loginPath.url);
maximize();
}
public void iniciarSesion(){
type("Qualityadmin", loginPath.txtUser);
type("pass1", loginPath.txtPass);
}
public void clickEnBoton(){
click(loginPath.btnLogin);
}
}
HomePage.java - I tried placing the chromeDriverConnection() again, but I get the same error
package page;
import Base.Base;
import paths.HomePath;
public class HomePage extends Base {
HomePath homePath = new HomePath();
public void mensajeExitoso() {
String mensaje = getText(homePath.txtMesajeExito);
System.out.println(mensaje);
}
}
Error
java.lang.NullPointerException
at Base.Base.getText(Base.java:35)
at page.HomePage.mensajeExitoso(HomePage.java:12)
at step.HomeStep.mensajeExitoso(HomeStep.java:10)
at stepdefinition.HomeStepDefinition.seMuestraUnMensajeDeExito(HomeStepDefinition.java:11)
at ✽.se muestra un mensaje de exito(file:///D:/Project/aer/features/src/test/resources/features/formulario.feature:22)
Process finished with exit code -1
Base.java - I don't think the error is in the Base class, but I put it anyway
Line 35: return driver.findElement (locator) .getText ();
package Base;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Base {
public WebDriver driver;
public Base(WebDriver driver){
this.driver = driver;
}
public Base() {
}
public WebDriver chromeDriverConnection() {
System.setProperty("webdriver.chrome.driver", "./src/test/resources/drivers/chromedriver.exe");
driver = new ChromeDriver();
return driver;
}
public WebElement findElement(By locator){
return driver.findElement(locator);
}
public String getText(WebElement element){
return element.getText();
}
public String getText(By locator){
return driver.findElement(locator).getText();
}
public void type(String inputText, By locator){
driver.findElement(locator).sendKeys(inputText);
}
public void iniciarSesion(String user, String pass){
}
public void click(By locator){
driver.findElement(locator).click();
}
Double num1 = 20.00;
String num2 = num1.toString();
public void visit(String url){
driver.get(url);
}
public void isDisplayed(By locator){
driver.findElement(locator).isDisplayed();
}
public void maximize(){
driver.manage().window().maximize();
}
}

Selenium webdriver gecko error: The path to the driver must be set by webdriver.gecko

trying to get selenium working but didn't work and showing me below error.
Libs:junit4.12, selenium-java-3.4, selenium-server-standalone-3.5
Could anyone take a look and tell me whats wrong with the code or what is
missing, please.
Every time when I start the test, I get 2 errors.
Screenshot embedded at the bottom showing the error details.
My code as below:
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class TestCase16 {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "URL";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ayre1de\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("URL");
}
#Test
public void testCaseAcandoIntranet() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("IDToken1")).clear();
driver.findElement(By.id("IDToken1")).sendKeys("XXX");
driver.findElement(By.id("IDToken2")).clear();
driver.findElement(By.id("IDToken2")).sendKeys("*XXX");
driver.findElement(By.name("Login.Submit")).click();
driver.findElement(By.id("yui_patched_v3_18_1_1_1502961326988_317")).click();
driver.findElement(By.xpath("//a[#id='_com_liferay_product_navigation_user_personal_bar_web_portlet_ProductNavigationUserPersonalBarPortlet_sidenavUserToggle']/span/div")).click();
driver.findElement(By.linkText("Abmelden")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
`
The problem is you are initializing webdriver instance two times like below. specially you have missed specifying the System.setProperty for the first instance of webdriver where exactly your code is failing:-
driver = new FirefoxDriver(); // 1st instance
baseUrl = "URL";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ayre1de\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(); // 2nd instance
driver.get("URL");
Now delete above two lines and write your code like below :-
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ayre1de\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("URL");

How to Upload a file into web browser using Winium?

I know I can upload file to browser with many ways such as: AutoIt, Robot Class, and other ways(I tried them all and they worked most of time).
I got introduced to Winium and I would like to make the same test case with it, that is, upload a file to a browser using it, but I did not know what to do to switch between web driver to winium driver. Please help because I searched a lot for this trick but could not find any result
package testUtilities;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.winium.WiniumDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class WiniumWeb
{
WebDriver driver;
#BeforeClass
public void setUp() throws IOException
{
driver = new FirefoxDriver();
driver.navigate().to("http://the-internet.herokuapp.com/upload");
driver.findElement(By.id("file-upload")).click();
String WiniumEXEpath = System.getProperty("user.dir") + "\\Resources\\Winium.Desktop.Driver.exe";
File file = new File(WiniumEXEpath);
if (! file.exists())
{
throw new IllegalArgumentException("The file " + WiniumEXEpath + " does not exist");
}
Runtime.getRuntime().exec(file.getAbsolutePath());
try
{
driver = new WiniumDriver(new URL("http://localhost:9999"), null);
} catch (MalformedURLException e)
{
e.printStackTrace();
}
}
#Test
public void testNotePade() throws InterruptedException
{
String file = System.getProperty("user.dir") + "\\Resources\\TestData.csv";
WebElement window = driver.findElement(By.className("File Upload"));
window.findElement(By.className("#32770")).sendKeys(file);
Thread.sleep(2000);
}
}
if you are still finding solution.I am sharing my script which worked for me.
public class FileUpload extends BaseClass {
static WiniumDriver d;
#BeforeClass
public void setUp() throws IOException {
DesktopOptions options = new DesktopOptions();
options.setApplicationPath("C:\\Windows\\System32\\openfiles.exe");
LaunchLocalBrowser("chrome","http://the-internet.herokuapp.com/upload");//use your own code to launch browser
driver.findElement(By.id("file-upload")).click();
String WiniumEXEpath = System.getProperty("user.dir") + "\\lib\\Winium.Desktop.Driver.exe";
File file = new File(WiniumEXEpath);
if (! file.exists()) {
throw new IllegalArgumentException("The file " + WiniumEXEpath + " does not exist");
}
Runtime.getRuntime().exec(file.getAbsolutePath());
try {
d = new WiniumDriver(new URL("http://localhost:9999"),options);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
#Test
public void testNotePade() throws InterruptedException {
String file = System.getProperty("user.dir") + "\\lib\\Testdata.txt";
d.findElementByName("File name:").sendKeys(file);
d.findElementByXPath("//*[#Name='Cancel']//preceding-sibling::*[#Name='Open']").click();
driver.findElement(By.id("file-submit")).click();
}
}
File upload using WiniumDriverService by referring to port- 9999. Creating winium instance using free port having issues. Below code is intended for sample implementation of Browser factory to facilitate web and desktop instances.
public class FactoryManager {
public static ClientFactory getIndividualProduct(EnumProductLists product) {
ClientFactory factory = null;
if (null != product) {
switch (product) {
case CHROME:
factory = new ProductChromeClient();
break;
case DESKTOP:
factory = new ProductWiniumClient();
break;
default:
break;
}
}
return factory;
}
}
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
import org.openqa.selenium.winium.WiniumDriverService;
public class ProductWiniumClient extends ClientFactory {
private WiniumDriverService service;
#Override
protected void startService() {
if (null == service) {
service = new WiniumDriverService.Builder()
.usingDriverExecutable(
new File(System.getProperty("user.dir") + "/WiniumFolder/Winium.Desktop.Driver.exe"))
.usingPort(9999).withVerbose(true).buildDesktopService();
try {
service.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
protected void createService() {
startService();
DesktopOptions options = new DesktopOptions();
options.setApplicationPath("C:\\Windows\\System32\\openfiles.exe");
deskClient = new WiniumDriver(service, options);
}
#Override
protected void stopService() {
if (null != service && service.isRunning()) {
service.stop();
}
}
}
public class TestCase1 {
WebDriver webClient;
WiniumDriver deskClient;
ClientFactory lists;
#BeforeTest
public void beforeTest() {
lists = FactoryManager.getIndividualProduct(EnumProductLists.CHROME);
webClient = (WebDriver) this.lists.getClient(WebDriver.class.getTypeName());
lists = FactoryManager.getIndividualProduct(EnumProductLists.DESKTOP);
deskClient = (WiniumDriver) this.lists.getClient("");
}
#Test
public void f() {
if (null != webClient) {
try {
webClient.manage().window().maximize();
webClient.get("https://uploadfiles.io/");
webClient.findElement(By.id("upload-window")).click();
String file = System.getProperty("user.dir") + "\\files\\upload.txt";
deskClient.findElement(By.name("File name:")).sendKeys(file);
deskClient.findElement(By.xpath("//*[#Name='Cancel']//preceding-sibling::*[#Name='Open']")).click();
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("Client Instance is Null!");
}
}
#AfterTest
public void afterTest() {
}
}

Selenium Webdriver pdf file signature location

I find it more difficult to get solution for my issue.
Actually i am trying to upload a pdf into a website and i need to open the uploaded file and i need to place a x mark in the document, where another person needs to sign.
I have done with the file upload and now i need to open the uploaded pdf and mark the x mark for signature. The x mark will be placed once you click inside the opened document with your mouse cursor.
I have listed my code below,
Please let me know how to clear this issue.
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Dasenddoc {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://pp.govreports.com.au/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testDasenddoc() throws Exception {
driver.get("https://ppaccounts.govreports.com.au/");
driver.findElement(By.id("UserName")).clear();
driver.findElement(By.id("UserName")).sendKeys("vignesh#eimpact.com.au");
driver.findElement(By.id("Password")).clear();
driver.findElement(By.id("Password")).sendKeys("Viki2607");
driver.findElement(By.id("UserName")).clear();
driver.findElement(By.id("UserName")).sendKeys("vignesh2016#eimpact.com.au");
driver.findElement(By.id("btnLogin")).click();
driver.get("https://ppda.govreports.com.au/");
//Thread.sleep(5000);
//WebDriverWait wait = new WebDriverWait(driver, 15);
//wait.until(ExpectedConditions.titleContains("My Documents - Digital Authenticatiion"));
Thread.sleep(5000);
driver.findElement(By.id("newdoc")).click();
driver.findElement(By.linkText("Send a Document")).click();
driver.findElement(By.name("files")).clear();
driver.findElement(By.name("files")).sendKeys("E:\\Vignesh\\Manual\\Documents\\ITR sample files\\Individual_Tax_Return__03072013022155765.pdf");
driver.findElement(By.xpath("/html/body/div[6]/div/div[2]/div[2]/div[3]/div/form/div[1]/div/div[2]/div/table/tbody/tr/td[4]")).click();
driver.findElement(By.id("Name")).clear();
driver.findElement(By.id("Name")).sendKeys("Vignesh K S");
driver.findElement(By.xpath("/html/body/div[6]/div/div[2]/div[2]/div[3]/div/form/div[1]/div/div[2]/div/table/tbody/tr/td[5]")).click();
driver.findElement(By.id("Email")).clear();
driver.findElement(By.id("Email")).sendKeys("vignesh#eimpact.com.au");
driver.findElement(By.id("Message")).clear();
driver.findElement(By.id("Message")).sendKeys("Hi Clients");
driver.findElement(By.xpath("/html/body/div[6]/div/div[2]/div[2]/div[3]/div/form/div[1]/div/div[2]/div/table/tbody/tr/td[8]/div")).click();
driver.findElement(By.id("PvtMessage")).clear();
driver.findElement(By.id("PvtMessage")).sendKeys("Hi Viki");
driver.findElement(By.id("saveprivatemsg")).click();
driver.findElement(By.id("Continue")).click();
Thread.sleep(10000);
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}

Selenium working in netbeans but not when converting the project to exe

Hi,
I'm trying to link selenium with my exe version of the java project so that selenium will be executed when clicking a button.
Selenium code is:
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Pay {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
String Enum;
String cpr;
public Pay(String nEnum){
Enum = nEnum;
this.cpr = "000";
}
public Pay(String nEnum, String nCpr){
Enum = nEnum;
this.cpr = nCpr;
}
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "A:\\Documents\\NetBeansProjects\\Electricity\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
baseUrl = "http://www.bahrain.bh/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
public void testRent() throws Exception {
driver.get(baseUrl + "/wps/portal/!ut/p/c5/04_SB8K8xLLM9MSSzPy8xBz9CP0os3gLAxNHQ093A3d_J29DA08_cw9TT1dvI8cgU_1wkA6zeGd3Rw8Tcx8DAwsXNwsDIydTM89AAxcDA09TiLwBDuBooO_nkZ-bqh-cmqdfkJ2d5uioqAgARs8Bqw!!/dl3/d3/L0lHSkovd0RNQU5rQUVnQSEhL1lCZncvYXI!/");
driver.findElement(By.cssSelector("a.toolbarLink > div")).click();
driver.findElement(By.xpath("//form[#id='viewns_7_804A1IG0GOBK10IN7H5IEK2AV1_:eServicesForm']/div/table/tbody/tr[7]/td[2]/table/tbody/tr/td[2]/a/span")).click();
driver.findElement(By.cssSelector("img[alt=\"Launch Service\"]")).click();
new Select(driver.findElement(By.id("viewns_7_OAHIGGG0GGV880I1V3LJ6130G3_:PayerLoginForm:mewIdType"))).selectByVisibleText("CPR");
driver.findElement(By.id("viewns_7_OAHIGGG0GGV880I1V3LJ6130G3_:PayerLoginForm:mewId")).clear();
driver.findElement(By.id("viewns_7_OAHIGGG0GGV880I1V3LJ6130G3_:PayerLoginForm:mewId")).sendKeys(cpr);
driver.findElement(By.id("viewns_7_OAHIGGG0GGV880I1V3LJ6130G3_:PayerLoginForm:mewAccountNo")).clear();
driver.findElement(By.id("viewns_7_OAHIGGG0GGV880I1V3LJ6130G3_:PayerLoginForm:mewAccountNo")).sendKeys(Enum);
driver.findElement(By.name("viewns_7_OAHIGGG0GGV880I1V3LJ6130G3_:PayerLoginForm:_id4")).click();
driver.findElement(By.cssSelector("input[type=\"checkbox\"]")).click();
driver.findElement(By.name("viewns_7_OAHIGGG0GGV880I1V3LJ6130G3_:_id0:_id1")).click();
driver.findElement(By.id("Debit Card")).click();
driver.findElement(By.xpath("//tr[7]/td[2]/span/label")).click();
driver.findElement(By.name("btnPay2")).click();
driver.findElement(By.name("Ecom_Payment_Card_Name")).clear();
driver.findElement(By.name("Ecom_Payment_Card_Name")).sendKeys("AAA");
driver.findElement(By.name("Ecom_Payment_Card_Number")).clear();
driver.findElement(By.name("Ecom_Payment_Card_Number")).sendKeys("123");
}
public void tearDown() throws Exception {
// driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
/*alert.dismiss();*/
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* #author Home
*/
I will call this class and pass it the needed information and execute the selenium code by calling the methods.
My code works perfectly when executed in netbeans however when convert it to exe file, I can't run selenium anymore.
The code of the other class which will run selenium methods:
String eNum = "123";
Pay p1 = new Pay(eNum);
try {
p1.setUp();
} catch (Exception ex) {
Logger.getLogger(Building1.class.getName()).log(Level.SEVERE, null, ex);
}
try {
p1.testRent();
} catch (Exception ex) {
Logger.getLogger(Building1.class.getName()).log(Level.SEVERE, null, ex);
}
try {
p1.tearDown();
} catch (Exception ex) {
Logger.getLogger(Building1.class.getName()).log(Level.SEVERE, null, ex);
}
Thank you...

Categories