Selenium Webdriver pdf file signature location - java

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;
}
}
}

Related

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");

Selenium Java - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property

My FireFox Version 49.0.1
Selenium Version: Selenium-java-3.0.0-beta3
Java: 8.0.1010.13
I have replaced all the existing Selenium Jar Files with the new files. Added the gecko.Driver to my code still I am seeing this message:
Error Message:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;
My Code:
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AbstractPage {
WebDriver Driver =new FirefoxDriver();
#Before
public void Homescreen() throws InterruptedException
{
System.getProperty("Webdriver.gecko.driver", "C:/geckodriver.exe");
System.setProperty("Webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Driver.get("URL");
Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#After
public void TestComplete() {
Driver.close();
}
#Test
public void Projects() {
Driver.findElement(By.id("login-form-username")).sendKeys("Login");
Driver.findElement(By.id("login-form-password")).sendKeys("Password");
Driver.findElement(By.id("quickSearchInput")).sendKeys("ID");
}
}
You can remove main() method from the code. unzip your gecko driver and save it to your local system with wires.exe.
my sample class path is
G:\ravik\Ravi-Training\Selenium\Marionette for firefox\wires.exe
public class AbstractPage
{
WebDriver Driver;
System.setProperty("WebDriver.gecko.Driver", "C:\\TEMP\\Temp1_geckodriver-v0.10.0-win64.zip");
Driver=new FirefoxDriver();
#Before
public void Homescreen() throws InterruptedException
{
Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Driver.get("https://QualityAssurance.com");
Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Driver.findElement(By.id("login-form-username")).sendKeys("Login");
Driver.findElement(By.id("login-form-password")).sendKeys("Password");
//JavascriptExecutor js = (JavascriptExecutor) Driver;
//js.executeScript("document.getElementById('login-form-password').setAttribute('value', val );");
}
#After
public void TestComplete() {
Driver.close();
}
#Test
public void Projects() {
Driver.findElement(By.id("quickSearchInput")).sendKeys("WMSSE-229");
Please replace below line
System.setProperty("WebDriver.gecko.Driver", C:\\TEMP\\Temp1_geckodriver-v0.10.0-win64.zip");
You should pass geckodriver.exe not Zip file.
String driverPath = "F:/Sample/Selenium3Example/Resources/";
System.setProperty("webdriver.firefox.marionette", driverPath+"geckodriver.exe");
You can make your code more cleaner when posting here.
You must do something like this:
System.setProperty("webdriver.gecko.driver", "C:/geckodriver.exe");
System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
This is a working example, it make you know the context what the above code snippet used
package selenium;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Junit4FirefoxJava {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
System.setProperty("webdriver.gecko.driver", "C:/geckodriver.exe");
System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
driver = new FirefoxDriver();
baseUrl = "http://www.bing.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testJunit4IeJava() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("sb_form_q")).click();
driver.findElement(By.id("sb_form_q")).clear();
driver.findElement(By.id("sb_form_q")).sendKeys("NTT data");
driver.findElement(By.id("sb_form_go")).click();
driver.findElement(By.linkText("NTT DATA - Official Site")).click();
driver.findElement(By.id("js-arealanguage-trigger")).click();
driver.findElement(By.linkText("Vietnam - English")).click();
driver.findElement(By.id("MF_form_phrase")).clear();
driver.findElement(By.id("MF_form_phrase")).sendKeys("internet");
driver.findElement(By.cssSelector("input.search-button")).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;
}
}
}

Selenium WebDriver NullPointerException while grabbing url

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!

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...

Selenium webdriver : <WebElement> Iterator cannot be resolved to a type

My Problem in brief :
Through My selenium web driver right now i am testing list of elements in a list box , While using the following code i am getting the error
Testing Configuration :
Mozilla firefox
Eclipse Indigo
Selenium Webdriver 2
Scenario which i tested :
Open website
Select and display the list box items
Write to console
My error :
java.lang.Error: Unresolved compilation problems: The type List is not generic; it cannot be parameterized with arguments Iterator cannot be resolved to a type
My Code :
package com.example.tests;
import java.util.Iterator;
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.WebElement;
import org.openqa.jetty.html.List;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import com.browsersetup.test.BrowserSetup;
import org.testng.*;
import org.testng.annotations.*;
import org.testng.annotations.Test;
#SuppressWarnings("unused")
public class sample2 extends BrowserSetup{
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#BeforeClass
public void setUp() throws Exception {
driver = new OperaDriver();
baseUrl = "http://www.ebay.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("Browser = " + driver);
System.out.println("Base URL = " + baseUrl);
}
#Test
public void testUntitled() throws Exception {
driver.get(baseUrl + "/");
Thread.sleep(10000);
WebElement element = driver.findElement(By.name("_sacat"));
Select dd= new Select(element);
List<WebElement> allOptions= dd.getOptions();
//To go through the list, we can use an Iterator.
//Iterator should be of the same type as the List
//which is WebElement in this case.
Iterator<WebElement> it = allOptions.iterator();
//Using while loop, we can iterate till the List has
//a next WebElement [hasNext() is true]
//number of items in the list
System.out.println(allOptions.size());
while(it.hasNext()){
//When you say it.next(), it points to a particular
//WebElement in the List.
WebElement el = it.next();
//Check for the required element by Text and click it
if(el.getText().equals("mango")){
System.out.println(el.getAttribute("value"));
el.click();
}
}
#AfterClass
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;
}
}
}
I dont know where it went wrong,guide me where it went wrong
thanks in advance
See the javadocs of org.openqa.jetty.html.List: http://www.jarvana.com/jarvana/view/org/seleniumhq/selenium/selenium-server/2.0b1/selenium-server-2.0b1-javadoc.jar!/org/openqa/jetty/html/List.html
and the one of the java.util.List: http://docs.oracle.com/javase/7/docs/api/java/util/List.html
The one you used doesn't support generics (as the error says).
The problem in your case seems to be the following import:
import org.openqa.jetty.html.List;
try to replace it with:
import java.util.List;
For more ideas see similar question: The type Collection is not generic; it cannot be parameterized with arguments <? extends E>

Categories