Getting started with webdriver requires some idea on “how to use the APIs” provided by the Selenium 2 Webdriver. Some of the useful APIs were discussed in detail in “Useful APIs of WebDriver”. Example of automating a web page with these APIs explains the Test Automation with WebDriver better.
I have created a sample web page which has different objects such as edit box, labels, links, buttons, radio button, checkbox, javascript popup, etc. Please download the same from the below link:
Unzip the file into local drive (C:\, D:\,etc)
Sample WebSite is used in the below example:
package com.selftechy.wdriverbasics; /* * Author - Seetaram Hegde * Copyrights - All rights reserved. * */ import java.util.List; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class CreateAccount { public static WebDriver driver; public Alert alert; @BeforeClass public static void setUpBeforeClass() throws Exception { driver=new FirefoxDriver(); driver.get("file:///C:/Sample%20Website/CreateAccount.htm"); } @Test public void testCreateAccount() throws InterruptedException{ navigatetoWebpage(driver,"file:///C:/Sample%20Website/CreateAccount.htm"); typeinEditbox(driver,"name","FirstName","Karthik"); typeinEditbox(driver,"name","Lname","Shetty"); typeinEditbox(driver,"xpath","//textarea[@name='street']","No. 425, 3rd Main, 7th Cross, 1st Sector, HSR Layout"); selectValue(driver,"Chennai"); selectValue(driver,"Tamilnadu"); selectValue(driver,"Germany"); selectRadiobutton(driver,"name","male"); selectCheckbox(driver,"name","kannada","ON"); selectCheckbox(driver,"name","english","ON"); selectCheckbox(driver,"name","hindi","ON"); clickButton(driver,"name","Save"); closeJscriptPopup(driver,alert); Thread.sleep(50); clickLink(driver,"xpath","//a[@href='CustomerInfo.htm']"); Thread.sleep(50); clickLink(driver,"xpath","//a[@href='CreateAccount.htm']"); } public static void closeJscriptPopup(WebDriver driver, Alert alert){ alert = driver.switchTo().alert(); alert.accept(); } public static void navigatetoWebpage(WebDriver driver, String url){ driver.get(url); } public static void clickButton(WebDriver driver, String identifyBy, String locator){ if (identifyBy.equalsIgnoreCase("xpath")){ driver.findElement(By.xpath(locator)).click(); }else if (identifyBy.equalsIgnoreCase("id")){ driver.findElement(By.id(locator)).click(); }else if (identifyBy.equalsIgnoreCase("name")){ driver.findElement(By.name(locator)).click(); } } public static void clickLink(WebDriver driver, String identifyBy, String locator){ if (identifyBy.equalsIgnoreCase("xpath")){ driver.findElement(By.xpath(locator)).click(); }else if (identifyBy.equalsIgnoreCase("id")){ driver.findElement(By.id(locator)).click(); }else if (identifyBy.equalsIgnoreCase("name")){ driver.findElement(By.name(locator)).click(); }else if (identifyBy.equalsIgnoreCase("name")){ driver.findElement(By.linkText(locator)).click(); }else if (identifyBy.equalsIgnoreCase("name")){ driver.findElement(By.partialLinkText(locator)).click(); } } public static void typeinEditbox(WebDriver driver, String identifyBy, String locator, String valuetoType){ if (identifyBy.equalsIgnoreCase("xpath")){ driver.findElement(By.xpath(locator)).sendKeys(valuetoType); }else if (identifyBy.equalsIgnoreCase("id")){ driver.findElement(By.id(locator)).sendKeys(valuetoType); }else if (identifyBy.equalsIgnoreCase("name")){ driver.findElement(By.name(locator)).sendKeys(valuetoType); } } public static void selectRadiobutton(WebDriver driver, String identifyBy, String locator){ if (identifyBy.equalsIgnoreCase("xpath")){ driver.findElement(By.xpath(locator)).click(); }else if (identifyBy.equalsIgnoreCase("id")){ driver.findElement(By.id(locator)).click(); }else if (identifyBy.equalsIgnoreCase("name")){ driver.findElement(By.name(locator)).click(); } } public static void selectCheckbox(WebDriver driver, String identifyBy, String locator, String checkFlag){ if (identifyBy.equalsIgnoreCase("xpath")){ if ((checkFlag).equalsIgnoreCase("ON")){ if (!(driver.findElement(By.xpath(locator)).isSelected())){ driver.findElement(By.xpath(locator)).click(); } } }else if (identifyBy.equalsIgnoreCase("id")){ if ((checkFlag).equalsIgnoreCase("ON")){ if (!(driver.findElement(By.id(locator)).isSelected())){ driver.findElement(By.id(locator)).click(); } } }else if (identifyBy.equalsIgnoreCase("name")){ if ((checkFlag).equalsIgnoreCase("ON")){ if (!(driver.findElement(By.name(locator)).isSelected())){ driver.findElement(By.name(locator)).click(); } } } } public static void selectValue(WebDriver driver, String valToBeSelected){ List <WebElement> options = driver.findElements(By.tagName("option")); for (WebElement option : options) { if (valToBeSelected.equalsIgnoreCase(option.getText())){ option.click(); } } } @AfterClass public static void tearDownAfterClass() throws Exception { System.out.println("Execution completed....."); //driver.quit(); //if you want to stop the webdriver after execution, then remove the comment } }
Above example showcases all the basic operations of Test Automation through Selenium 2 WebDriver. Try to replicate the code and execute.
This should fill up the form, clicks save & closes the popup, and then navigates to the other page and comes back by clicking the links on the page.
Hi, This sounds good to me. i got a problem here. I want to run this code against Internet Explorer. so is this possible to provide right command for IE.
for firefox you used …. -> “driver=new FirefoxDriver();”
for IE …… -> ?
Thanks,
Pavan
i found this…. it’s InternetExplorerDriver();
If I run this I am getting “java.lang.NullPointerException” error message. may I know what could be the reason.
Thanks,
Pavan
Yes, you need to use InternetExplorerDriver(). Provide me exception stacktrace. Otherwise, it is difficult to findout from where NullPointerException is coming. Meaning of Nullpointerexception is “Java is expecting some value and the actual value is NULL” so it is throwing error.
Hello!
The above codes worked perfectly when I use FirefoxDriver(). However, it is not the case when I am using the Internet explorer 8. Could you please enlighten us?
I have modified the setUpBeforeClass() as follows:
public static void setUpBeforeClass() throws Exception {
DesiredCapabilities ieCapabilities = DesiredCapabilities
.internetExplorer();
ieCapabilities
.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
File file = new File(“C:/Selenium/IEDriverServer.exe”);
System.setProperty(“webdriver.ie.driver”, file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
//driver=new FirefoxDriver();
driver.get(“file:///C:/Sample%20Website/CreateAccount.htm”);
}
I get the following error when running as JUnit:
java.lang.NullPointerException
at CreateAccount2.navigatetoWebpage(CreateAccount2.java:74)
at CreateAccount2.testCreateAccount(CreateAccount2.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Please, provide us with a tutorial on Selenium and Internet Explorer Driver.
Thanks in anticipation.
Hi
While running this program i am getting following error.
CreateAccount.java:2: class, interface, or enum expected
package org.junit.*;
^
CreateAccount.java:3: class, interface, or enum expected
package org.openqa.selenium.*;
^
how can i solve this issue. please help me.
Thanks
prathibha
@Prathibha,
Please add latest junit & Selenium 2.0 Webdriver JAR files to the classpath (Project ->Right click ->properties -> build path -> Add External Jar
Hi
while running this program in the text editor. package org.openqa.selenium is giving the error as class, interface or enum expected. this one is not resolved.
I written the following program. But i can’t run it in the cross browsers. while the compilation itself the class, interface or enum expected error is given.
package com.example.tests;
package com.thoughtworks.selenium;
package org.openqa.selenium;
package org.openqa.selenium.htmlunit;
package org.openqa.selenium.chrome;
package org.testing.annotations;
package org.testing;
import com.thoughtworks.selenium.Selenium;
import org.openqa.selenium.*;
import org.openqa.selenium.htmlunit.*;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chrome.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
public class AdminChallenge {
WebDriver driver;
Selenium selenium;
@BeforeMethod
public void startSelenium() {
driver = new chromeDriver();
selenium = new WebDriverBackedSelenium(driver, “http://202.53.13.107:7100/node/add/challenge”);
}
@AfterMethod
public void stopSelenium() {
driver.close();
}
@Test
public void testAdminChallenge() {
selenium.open(“http://202.53.13.107:7100/node/add/challenge”);
assertEquals(selenium.getTitle(), “Submit Challenge | WCED Desgin”);
assertTrue(selenium.getText(“css=label”).matches(“^exact:Title: [\\s\\S]*$”));
selenium.highlight(“css=label”);
assertTrue(selenium.isElementPresent(“id=edit-title”));
assertTrue(selenium.isVisible(“id=edit-title”));
assertEquals(selenium.getText(“id=edit-title”), “”);
selenium.highlight(“id=edit-title”);
assertTrue(selenium.getText(“css=#edit-field-chall-description-0-value-wrapper > label”).matches(“^exact:Description: [\\s\\S]*$”));
selenium.highlight(“css=#edit-field-chall-description-0-value-wrapper > label”);
assertTrue(selenium.isElementPresent(“id=edit-title”));
selenium.highlight(“id=edit-title”);
assertTrue(selenium.isElementPresent(“id=edit-field-chall-description-0-value”));
selenium.highlight(“id=edit-field-chall-description-0-value”);
assertTrue(selenium.getText(“css=#edit-field-chall-details-0-value-wrapper > label”).matches(“^exact:Details: [\\s\\S]*$”));
selenium.highlight(“css=#edit-field-chall-details-0-value-wrapper > label”);
assertTrue(selenium.isElementPresent(“id=edit-field-chall-details-0-value”));
selenium.highlight(“id=edit-field-chall-details-0-value”);
assertEquals(selenium.getText(“css=div.description”), “Enter the short description of the article.”);
selenium.highlight(“css=div.description”);
assertTrue(selenium.getText(“css=#edit-field-chall-main-image-0-upload-wrapper > label”).matches(“^exact:Challenge Image: [\\s\\S]*$”));
selenium.highlight(“css=#edit-field-chall-main-image-0-upload-wrapper > label”);
assertTrue(selenium.isElementPresent(“css=#edit-field-chall-main-image-0-upload-wrapper > label”));
assertEquals(selenium.getText(“id=edit-field-chall-main-image-0-upload”), “”);
assertTrue(selenium.isElementPresent(“id=edit-field-chall-main-image-0-upload”));
selenium.highlight(“id=edit-field-chall-main-image-0-upload”);
assertTrue(selenium.isElementPresent(“class=form-submit ahah-processed”));
selenium.highlight(“class=form-submit ahah-processed”);
assertEquals(selenium.getText(“css=div.widget-edit > #edit-field-chall-main-image-0-upload-wrapper > div.description”), “Maximum file size: 40 MB\nAllowed extensions: png gif jpg jpeg”);
selenium.highlight(“css=div.widget-edit > #edit-field-chall-main-image-0-upload-wrapper > div.description”);
assertEquals(selenium.getText(“css=#edit-field-chall-main-image-0-upload-wrapper > div.description”), “Upload the challenge image”);
selenium.highlight(“css=#edit-field-chall-main-image-0-upload-wrapper > div.description”);
assertEquals(selenium.getText(“css=thead.tableHeader-processed > tr > th”), “Documents:”);
selenium.highlight(“css=thead.tableHeader-processed > tr > th”);
assertEquals(selenium.getText(“id=edit-field-chall-document-0-upload”), “”);
selenium.highlight(“id=edit-field-chall-document-0-upload”);
assertEquals(selenium.getText(“id=edit-field-chall-document-0-filefield-upload”), “”);
selenium.highlight(“id=edit-field-chall-document-0-filefield-upload”);
assertEquals(selenium.getText(“css=div.widget-edit > #edit-field-chall-document-0-upload-wrapper > div.description”), “Maximum file size: 40 MB\nAllowed extensions: txt pdf doc odt”);
selenium.highlight(“css=div.widget-edit > #edit-field-chall-document-0-upload-wrapper > div.description”);
assertTrue(selenium.isElementPresent(“css=div.handle”));
assertEquals(selenium.getText(“css=div.handle”), “”);
selenium.highlight(“css=div.handle”);
assertEquals(selenium.getText(“css=#field-chall-document-items > div.description”), “Upload challenge document”);
selenium.highlight(“css=#field-chall-document-items > div.description”);
assertEquals(selenium.getText(“id=edit-field-chall-document-field-chall-document-add-more”), “”);
selenium.highlight(“id=edit-field-chall-document-field-chall-document-add-more”);
assertTrue(selenium.getText(“css=#edit-field-chall-end-date-0-value-wrapper > label”).matches(“^exact:End Date: [\\s\\S]*$”));
selenium.highlight(“css=#edit-field-chall-end-date-0-value-wrapper > label”);
assertEquals(selenium.getText(“id=edit-field-chall-end-date-0-value-datepicker-popup-0”), “”);
selenium.highlight(“id=edit-field-chall-end-date-0-value-datepicker-popup-0”);
assertEquals(selenium.getText(“css=#edit-field-chall-end-date-0-value-datepicker-popup-0-wrapper > div.description”), “Format: 2 August 2011”);
selenium.highlight(“css=#edit-field-chall-end-date-0-value-datepicker-popup-0-wrapper > div.description”);
assertTrue(selenium.isTextPresent(“exact:Knowledge Hub: *”));
assertTrue(selenium.getText(“css=#field_chall_kw_reference_values > thead.tableHeader-processed > tr > th”).matches(“^exact:Knowledge Hub: [\\s\\S]*$”));
selenium.highlight(“css=#field_chall_kw_reference_values > thead.tableHeader-processed > tr > th”);
assertEquals(selenium.getText(“class=handle”), “”);
selenium.highlight(“css=html.js body#pid-node-add-challenge.not-front div#page.page div#page-inner.page-inner div#main-wrapper.main-wrapper div#main.main div#main-inner.main-inner div#main-group.main-group div#main-group-inner.main-group-inner div#main-content.main-content div#main-content-inner.main-content-inner div#content-group.content-group div#content-group-inner.content-group-inner div#content-region.content-region div#content-region-inner.content-region-inner div#content-inner.content-inner div#content-inner-inner.content-inner-inner div#content-content.content-content form#node-form div div.node-form div.standard div#field-chall-kw-reference-items table#field_chall_kw_reference_values.content-multiple-table tbody tr.draggable td.content-multiple-drag a.tabledrag-handle div.handle”);
assertEquals(selenium.getText(“id=edit-field-chall-kw-reference-0-nid-nid”), “”);
selenium.highlight(“id=edit-field-chall-kw-reference-0-nid-nid”);
assertEquals(selenium.getText(“edit-field-chall-kw-reference-field-chall-kw-reference-add-more”), “”);
selenium.highlight(“edit-field-chall-kw-reference-field-chall-kw-reference-add-more”);
assertTrue(selenium.getText(“css=#field_chall_org_reference_values > thead.tableHeader-processed > tr > th”).matches(“^exact:Organisation: [\\s\\S]*$”));
selenium.highlight(“css=#field_chall_org_reference_values > thead.tableHeader-processed > tr > th”);
assertEquals(selenium.getText(“id=edit-field-chall-org-reference-0-nid-nid”), “”);
selenium.highlight(“id=edit-field-chall-org-reference-0-nid-nid”);
assertEquals(selenium.getText(“id=edit-field-chall-org-reference-field-chall-org-reference-add-more”), “”);
selenium.highlight(“id=edit-field-chall-org-reference-field-chall-org-reference-add-more”);
assertTrue(selenium.getText(“css=#edit-field-chall-detailpage-image-0-upload-wrapper > label”).matches(“^exact:Challenge Details Page image: [\\s\\S]*$”));
selenium.highlight(“css=#edit-field-chall-detailpage-image-0-upload-wrapper > label”);
assertEquals(selenium.getText(“id=edit-field-chall-detailpage-image-0-upload”), “”);
assertTrue(selenium.getText(“css=#edit-field-chall-detailpage-image-0-upload-wrapper > label”).matches(“^exact:Challenge Details Page image: [\\s\\S]*$”));
selenium.highlight(“id=edit-field-chall-detailpage-image-0-upload”);
assertEquals(selenium.getText(“id=edit-field-chall-detailpage-image-0-filefield-upload”), “”);
selenium.highlight(“id=edit-field-chall-detailpage-image-0-filefield-upload”);
assertEquals(selenium.getText(“id=edit-submit”), “”);
selenium.highlight(“id=edit-submit”);
assertEquals(selenium.getText(“id=edit-preview”), “”);
selenium.highlight(“id=edit-preview”);
selenium.click(“id=edit-submit”);
selenium.waitForPageToLoad(“30000”);
assertEquals(selenium.getText(“class=messages error”), “Title field is required. Description field is required. Details field is required. End date field is required. Knowledge Hub field is required. Organization field is required. Challenge Image field is required. Challenge Details Page image field is required.”);
selenium.typeKeys(“id=edit-title”, “!@#$%^&”);
selenium.type(“id=edit-field-chall-description-0-value”, “!@#$%^&*(SDFGRTVB BNnvjdsnvjn”);
selenium.click(“edit-submit”);
selenium.waitForPageToLoad(“30000”);
assertEquals(selenium.getText(“class=messages error”), “The title field is invalid. Details field is required. end date field is required. Knowledge Hub field is required. Organization field is required. Challenge Image field is required. Challenge Details page image field is required.”);
selenium.type(“edit-title”, “6482370892704”);
selenium.type(“id=edit-field-chall-description-0-value”, “37897903749203942487294839849!@#$%^&*()”);
selenium.type(“id=edit-field-chall-details-0-value”, “837482709!@#$%^&*”);
selenium.type(“id=edit-field-chall-main-image-0-upload”, “/home/prathibha/Pictures/images/flowers28.jpg”);
selenium.type(“id=edit-field-chall-end-date-0-value-datepicker-popup-0”, “2312”);
selenium.click(“edit-submit”);
assertEquals(selenium.getText(“class=messages error”), “Field end date is inavalid. Knowledge Hub field is required. Organization field is required. Challenge Details Page image field is required.”);
selenium.type(“edit-title”, “–“);
selenium.type(“id=edit-field-chall-description-0-value”, “?><<?&^%$#W$@$EDRE%T&(&*(*_()*+)HUGT%E#@W#D$");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flowers28.jpg");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "2/9/2011");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "!@#$%^&");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "!@#$%^&*()^&(");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "The titlt field is invalid. Field end date is invlid. Knowledge Hub: found no valid poast with that title. Organization: found no valid post with that title. Challenge details Page image field is required.");
selenium.type("edit-title", "___");
selenium.type("id=edit-field-chall-description-0-value", "This is the description of the challenge.");
selenium.type("id=edit-field-chall-details-0-value", "This is the details of challenge.");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "02-09-2011");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "12334444556");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "578689687");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "The title field is invalid. Field end date is invalid. Knowledge Hub: found no valid post with that title. Organization: found no valid post with that title. Challenge details Page image field is required.");
selenium.type("edit-title", "hvhg43543545");
selenium.type("id=edit-field-chall-description-0-value", "This is the description of the challenge.");
selenium.type("id=edit-field-chall-details-0-value", "This is the details of challenge.");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "02-09-2011");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "12334444556");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "578689687");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "The title field is invalid. Field end date is invalid. Knowledge Hub: found no valid post with that title. Organization: found no valid post with that title. Challenge details Page image field is required.");
selenium.type("edit-title", "1234214326456457");
selenium.type("id=edit-field-chall-description-0-value", "This is the description of the challenge.");
selenium.type("id=edit-field-chall-details-0-value", "This is the details of challenge.");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "02-09-2011");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "12334444556");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "578689687");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "The Title field is not valid. Field end date is invalid. Knowledge Hub: found no valid post with that title. Organization: found no valid post with that title. Challenge details Page image field is required.");
selenium.type("edit-title", "……");
selenium.type("id=edit-field-chall-description-0-value", "b,.n/nkljiou9u86786");
selenium.type("id=edit-field-chall-details-0-value", "b.nkhuiyy7678687uhgu");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower2.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "2 September 2012");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "Knowledge Hub 1");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "Organisation3");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "The title field is invalid. Challenge Details Page image field is required.");
selenium.type("edit-title", "challenge 4");
selenium.type("id=edit-field-chall-description-0-value", "This is the description of the challenge.");
selenium.type("id=edit-field-chall-details-0-value", "This is the details of challenge.");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "02 NOVEMBER 2012");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "knowledgehub 2");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "organization1");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "Feild End Date is invalid. Knowledge Hub: found no valid post with that title. Organisation: found no valid post with that title. Challenge Details Page Image field is required.");
selenium.type("edit-title", "challenge 7");
selenium.type("id=edit-field-chall-description-0-value", "b,.n/nkljiou9u86786");
selenium.type("id=edit-field-chall-details-0-value", "b.nkhuiyy7678687uhgu");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "2 September 2012");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "Knowledge Hub 1");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "Organisation3");
selenium.type("id=edit-field-chall-detailpage-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages status"), "Challenge challenge 7 has been created. No posts in this group.");
selenium.type("edit-title", "challenge 7");
selenium.type("id=edit-field-chall-description-0-value", "b,.n/nkljiou9u86786");
selenium.type("id=edit-field-chall-details-0-value", "b.nkhuiyy7678687uhgu");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "2 September 2012");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "Knowledge Hub 1");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "Organisation3");
selenium.type("id=edit-field-chall-detailpage-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "The Challenge name is already exist.");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "Jannuary 45 2019");
selenium.click("edit-submit");
assertEquals(selenium.getText("class=messages error"), "Title field is required. Description field is required. Details field is required. Field end date is inavalid. Challenge Image is required. Knowledge Hub field is required. Organization field is required. Challenge Details Page Image field is required.");
selenium.type("edit-title", "challenge 8");
selenium.type("id=edit-field-chall-description-0-value", "b,.n/nkljiou9u86786");
selenium.type("id=edit-field-chall-details-0-value", "jhdfkjshfjksk");
selenium.type("id=edit-field-chall-main-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.type("id=edit-field-chall-end-date-0-value-datepicker-popup-0", "2 September 2012");
selenium.type("id=edit-field-chall-kw-reference-0-nid-nid", "Knowledge Hub 1");
selenium.type("id=edit-field-chall-org-reference-0-nid-nid", "Organisation3");
selenium.type("id=edit-field-chall-detailpage-image-0-upload", "/home/prathibha/Pictures/images/flower1.png");
selenium.click("edit-preview");
selenium.waitForPageToLoad("30000");
assertEquals(selenium.getTitle(), "Preview | WCED Desgin");
selenium.click("edit-submit");
}
}
this is a hard coded script. can u explain how can i write the scripts without hard-code. I am new to selenium. and i am using ubuntu OS(it is a linux version). i am not using any java editors to write the scripts. can u pls provide me the solutions to write the script without hard code and how can i run the scripts in cross browsers.
@Prathibha:
Try running some sample scripts like Gmail – Login using the Xpath notations that you can get from FireBug. This should help you start on understanding things better and easy
@Sitaram:
Unable to locate a node using //span[@class=’toolbarButton’]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.0rc3’, revision: ‘12536’, time: ‘2011-06-20 18:19:52’
System info: os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.6.0_23′
Driver info: driver.version: HtmlUnitDriver
org.openqa.selenium.NoSuchElementException: Unable to locate a node using //span[@class=’toolbarButton’]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
I see this exception while using WebDriver. Could you please help me?
Try to change the driver to Firefoxdriver and see if it works… and one more thing, please put the xpath (//span…) into selenium IDE and click on the Find button.. if it highlights the object.. then only it works…
@Seetaram:
Could you please give me a sample program running in multiple browser(FireFox and IE ) parallel using Selenium 2.0 Webdriver and tesgNG
Thanks for your wonderful blog….
Will try to give you by tomorrow..
@ Anantha
Hello dear,
Could you share the sample program running in multiple browser please? I am experiencing some difficulties with IE. thanks 🙂
Nusha
Hi,
It’s really good implementation of webdriver.
I have requirement to do some mouse operations like mouseDown,mouseMove etc, can I know how to implement the same in Webdriver
Thanks in Advance
Sushruth
Hi Seetaram,
I noticed a problem in the script. Because Delhi is under both City and State, if selectValue is Delhi for one of them, both City and State will be set to Delhi. How would you modify selectValue so that it works properly?
FYI, I have a similar issue on a page I’m trying to automate as well. Your help is greatly appreciated.
Hi,
I am getting the following exception while trying to run the code :
java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:45)
at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:52)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:77)
at GoogleSearch.Search.setUpBeforeClass(Search.java:25)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I added all the external jars required but still couldn’t get the code running.
Could you please let me know what I am missing here ?
Thanks in advance,
Shikha
Hello Shikha,
Add Selenium-standalone-server.2.x.jar to buildpath
Thanks Seetaram, that worked !
Hi,
Download Sample Webpage link is not working. I am trying to download but not able to download it.
Check whether the firewall is blocking the download link… because it is perfectly working fine…
Hi seetaram, can you write one example program for mouse hovering option in web driver. Hovering a menu item and selecting sub-menu item.
It would be grt if you just hare an example to capture the Auto completion elements cam from AJAX response. I am struggling with that.
Much appreciated.
Thanks in advance.
regards
UdayB
Hi Uday hope the following code solves your query the code is for Selenium RC…
selenium.typeKeys(“county_search”, “lake”);
for (int second = 0;; second++) {
if (second >= 60) fail(“timeout”);
try { if (selenium.isTextPresent(“Lake County, IL”)) break; } catch (Exception e) {}
Thread.sleep(1000);
}
selenium.mouseOver(“//html/body/ul/li/a[. = \”Lake County, IL\”]”);
selenium.click(“//html/body/ul/li/a[. = \”Lake County, IL\”]”);
This code is not working for me, it is not opening Firefox browser and a link.
Can you please let me know can we write this in Junit test case or Java Class?
Hi Sitaram,
This is an excellent code i ever seen for selenium.
I have a website where on every login i got a SSL certificate (Security certificate) because i am using HTTPS:….
Could you please let me know is there any other way to handle security certificates.
Thanks in advance.
Mahesh
create a new firefox profile and use it.. that will eliminate your problem…
Hi Sitaram,
Thanks for your response, but with firefox also i am getting SSL certificate (Security certificate) on each login. But when i tried it with selenium server it shows SSL once in a day and after clicking on continue to the site its work fine for the day.
Please provide your input.
Thanks
Mahesh
Is there any other way to avoid SSL certificate?
Can you give me with example how to use regular expression in xpath/id…
//img[contains(@class,’nodeImage’)]
can i write as //img[contains(@class,’*.Image’)] ?
Thanks for writing such an ean-nto-usderstayd article on this topic.
Hi Sitaram,
This is excellent article, could you please let me know how we can perform data driven testing using excel sheet in selenium webdriver 2
I have explained in one of the posts on this blog, how to read the data from excel. You can also use “@RunWith(value = Parameterized.class)” & @Parameters annotation to make your tests data driven… do some research on google as well as use the post on excel on this blog..
Hi Seetaram,
i am getting below errors while running ur sample example.pls let me know what is the problem
org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”//a[@href=’CreateAccount.htm’]”}
Command duration or timeout: 50 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.19.0’, revision: ‘15849’, time: ‘2012-02-08 16:12:19’
System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.6.0_27′
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:123)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:439)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:226)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:299)
at org.openqa.selenium.By$ByXPath.findElement(By.java:344)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:218)
at selfw.CreateAccount.clickLink(CreateAccount.java:72)
at selfw.CreateAccount.testCreateAccount(CreateAccount.java:48)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {“method”:”xpath”,”selector”:”//a[@href=’CreateAccount.htm’]”}
Build info: version: ‘2.19.0’, revision: ‘15849’, time: ‘2012-02-08 16:12:19’
System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.6.0_27’
Driver info: driver.version: unknown
at .(file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/resource/modules/atoms.js:9476)
at .(file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js -> file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/firefoxDriver.js:402)
at .(file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js -> file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/firefoxDriver.js:427)
at .(file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:268)
at .(file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10251)
at .(file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10256)
at .(file:///C:/Users/rajesh/AppData/Local/Temp/anonymous2816370352052882524webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10204)
page might have changed.. try to find the element using correct xpath… the problem you are facing is that wrong xpath…
Hello,
I am not able to download the above rar file ?? pls make it public.
Thanks
Hi
Can any one explain me how to spilt this code and then execute, I mean , I wanted to create the functions in separate package and main function (@test) in one package and call the package.
I tried in that way but driver is throwing error message. Please let me know where I have to create a set up method to invoke driver..
because in the functions am not created any driver . should I create a driver in all the functios separately.. (@ before).
m creating one frmaework using webdriver… ther I have to create separate packages for all the functions.. and my final script should call all the functions..
Pls help me..
Hi
I tried to get the value from the output field using get text() function but not getting the value. below is the code.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Web_Calc_001 {
/**
* @param args
*/
public static void main(String[] args) {
WebDriver FFDriver = new FirefoxDriver();
FFDriver.get(“http://web2.0calc.com/”); //Open the browser
FFDriver.findElement(By.id(“num7”)).click();
FFDriver.findElement(By.id(“A42”)).click();
FFDriver.findElement(By.id(“num8”)).click();
FFDriver.findElement(By.id(“btn_equal”)).click();
String OP = FFDriver.findElement(By.id(“input”)).getText();
System.out.println(“The sum of 2 numbers is “+ OP);
}
}
is this throws error.. ?? what is the behavior after the execution…
Hi Seetaram,
I am getting the following error while trying to run the above program using InternetExplorerDriver()
It is actually invoking the browser and loading the page but thereafter it fails throwing the following error message:
May 27, 2012 7:54:27 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
May 27, 2012 7:54:27 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Execution completed…..
Please help.
Can you please elaborate… I need some more info…
hi seetaram,
simply superb post. thanks.
Hi Seetaram,
I am new to Webdriver and selinium.
While executing the below code I am getting issues with Internet Explorer Driver as well as firefox driver.
The detailed error stack trace has been provided below.
Could you please look into this and let me know where exactly I am going wrong for each of the driver.
Thanks and Regards,
Subrat
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.Alert;
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.ie.InternetExplorerDriver;
public class CreateAccount {
public static WebDriver driver;
public Alert alert;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
driver=new InternetExplorerDriver();
}
@Test
public void testCreateAccount() throws InterruptedException{
navigatetoWebpage(driver,”file:///E:/MyFiles/SeliniumTest/SampleWebsite/CreateAccount.htm”);
Thread.sleep(1000);
typeinEditbox(driver,”name”,”FirstName”,”Karthik”);
typeinEditbox(driver,”name”,”Lname”,”Shetty”);
typeinEditbox(driver,”xpath”,”//textarea[@name=’street’]”,”No. 425, 3rd Main, 7th Cross, 1st Sector, HSR Layout”);
}
public static void navigatetoWebpage(WebDriver driver, String url){
driver.get(url);
}
public static void typeinEditbox(WebDriver driver, String identifyBy, String locator, String valuetoType){
if (identifyBy.equalsIgnoreCase(“xpath”)){
driver.findElement(By.xpath(locator)).sendKeys(valuetoType);
}else if (identifyBy.equalsIgnoreCase(“id”)){
driver.findElement(By.id(locator)).sendKeys(valuetoType);
}else if (identifyBy.equalsIgnoreCase(“name”)){
driver.findElement(By.name(locator)).sendKeys(valuetoType);
}
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println(“Execution completed…..”);
//driver.quit(); //if you want to stop the webdriver after execution, then remove the comment
}
}
Error Message: (IE is getting invoked)
Jul 15, 2012 10:34:42 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed
Jul 15, 2012 10:34:42 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
With Firefox Driver: (Firefox is not getting invoked)
org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: XP
Build info: version: ‘2.7.0’, revision: ‘13926’, time: ‘2011-09-23 13:25:56’
System info: os.name: ‘Windows XP’, os.arch: ‘x86’, os.version: ‘5.1’, java.version: ‘1.6.0_25’
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.(Executable.java:53)
at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:60)
at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:56)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:79)
at webdriver.CreateAccount.setUpBeforeClass(CreateAccount.java:21)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
java.lang.NullPointerException
at webdriver.CreateAccount.tearDownAfterClass(CreateAccount.java:136)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I am using firefox 13.0.1.
Thanks and Regards,
Subrat
HI Seetharam,
I tried to run the example you have mentioned above. It didn’t show any warnings or errors in eclipse. But when I run the test failed. Please find the error below.
Execution completed…..
FAILED: testCreateAccount
java.lang.NullPointerException
at NewPac.CreateAccount.navigatetoWebpage(CreateAccount.java:51)
at NewPac.CreateAccount.testCreateAccount(CreateAccount.java:26)
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:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:715)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:907)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1237)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
at org.testng.TestNG.run(TestNG.java:1030)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Please help me to run this test successfully.
Many Thanks,
Sanjay
java.lang.NullPointerException
at NewPac.CreateAccount.navigatetoWebpage(CreateAccount.java:51)
The above exception tells that the object is null, so make sure that the object is properly created, try to debug step by step…
Hello Sanjay!
Could you run your codes successfully using IE?
Let me know asap… need help!
Nusha
Hello!
The above codes worked perfectly when I use FirefoxDriver(). However, it is not the case when I am using the Internet explorer 8. Could you please enlighten us?
I have modified the setUpBeforeClass() as follows:
public static void setUpBeforeClass() throws Exception {
DesiredCapabilities ieCapabilities = DesiredCapabilities
.internetExplorer();
ieCapabilities
.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
File file = new File(“C:/Selenium/IEDriverServer.exe”);
System.setProperty(“webdriver.ie.driver”, file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
//driver=new FirefoxDriver();
driver.get(“file:///C:/Sample%20Website/CreateAccount.htm”);
}
I get the following error when running as JUnit:
java.lang.NullPointerException
at CreateAccount2.navigatetoWebpage(CreateAccount2.java:74)
at CreateAccount2.testCreateAccount(CreateAccount2.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Please, provide us with a tutorial on Selenium and Internet Explorer Driver.
Thanks in anticipation.
check from where the Nullpointer is coming
Hi seetaram,
When i tried to run webdriver script i am getting below message
Exception in thread “main” org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.6.0_37’
Driver info: driver.version: firefox
System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.6.0_37’
Driver info: driver.version: firefox
at org.openqa.selenium.firefox.internal.ExtensionConnectionFactory.connectTo(ExtensionConnectionFactory.java:46)
at org.openqa.selenium.firefox.FirefoxDriver.connectTo(FirefoxDriver.java:139)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:129)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:109)
at GoogleTest.main(GoogleTest.java:15)
Caused by: org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.6.0_37’
Driver info: driver.version: firefox
at org.openqa.selenium.firefox.internal.SocketLock.lock(SocketLock.java:72)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.(NewProfileExtensionConnection.java:45)
at org.openqa.selenium.firefox.internal.ExtensionConnectionFactory.connectTo(ExtensionConnectionFactory.java:44)
… 4 more
I have added all the jar files to buildpath and selenium-standalone-2.x.jar file also added to the path.
I am using windows7, firefox16, eclipseVersion: Juno Release
Build id: 20120614-1722
Could you please let me know how can i fix this problem and run my code…
Thanks in advance
Can you please tell me How to Handle Multiple Windows
Need more info
Hi,
how to automate the regretion test suite using selenium webdriver.
please explain the steps we have to fallow.
Thank you very much.. very useful and self explanatory ..Great job sir….
Hi,
I am trying to write an excel sheet which is already exist.
But I am getting an error for Label; and add Cell.
Please help me to resolve it.