I am using selenium with maven and java language. I'm following page object design pattern. I tried so many times same error came. Anybody please correct this..
Here is the code.
html code:
<ul id="leftMenu" class="clearfix">
<li class="topmenu ltopmenu-display-event"><a href="http://qmsadm.local/dashboard"><span class="ico fa fa-fw
fa-dashboard
"></span>Dashboard</a></li><li class="topmenu
ltopmenu-display-event"><a href="javascript:void(0)"><span class="ico
fa fa-fw fa-globe
"></span>Admin</a><ul><li><a
href="http://qmsadm.local/admin/users"><span class="ico fa fa-fw
fa-users
"></span>Users</a></li><li><a
href="http://qmsadm.local/admin/roles"><span class="ico fa fa-fw
fa-user-md
PageObjects:
package pageobjects;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.ui.Select;
/**
* Created by naveen on 29/11/16.
*/
public class ClientPage {
//add client
@FindBy(linkText="Admin")
WebElement admin;
@FindBy(linkText="Clients")
WebElement clients;
@FindBy(how = How.XPATH, using = "//*[@id=\'search-container\']/a/i")
WebElement addClient;
@FindBy(how= How.ID, using= "name")
WebElement name;
@FindBy(how= How.ID, using= "group_id")
WebElement group_dropdown;
@FindBy(how= How.ID, using= "address")
WebElement address;
@FindBy(how= How.ID,using= "status")
WebElement status_dropdown;
@FindBy(how= How.ID, using= "lat")
WebElement lat;
@FindBy(how= How.ID, using= "lang")
WebElement lang;
@FindBy(how= How.CLASS_NAME, using= "btn-primary")
WebElement buton;
//click on admin
public void clickOnAdmin()
{
admin.click();
}
public void clickOnClients(){clients.click();}
public void clickOnAddClient()
{
addClient.click();
}
public void clickOnName(String nam)
{
name.sendKeys(nam);
}
public void select_List(String grpid)
{
Select group_id=new Select(group_dropdown);
group_id.selectByVisibleText(grpid);
}
public void enterAddress(String add)
{
address.sendKeys(add);
}
public void select_status(String stat)
{
Select status=new Select(status_dropdown);
status.selectByVisibleText(stat);
}
public void enter_Lat(String l)
{
lat.sendKeys(l);
}
public void enter_long(String lng)
{
lang.sendKeys(lng);
}
public void clickOnSubmit()
{
buton.click();
}
}
Steps:
package steps;
import org.openqa.selenium.support.PageFactory;
import pageobjects.ClientPage;
import util.DriverManager;
/**
* Created by naveen on 30/11/16.
*/
public class clientsteps {
public ClientPage Login(String nam, String grp, String add, String st, String lat, String log)
{
ClientPage clientPageObj = PageFactory.initElements(DriverManager.driver,ClientPage.class);
clientPageObj.clickOnAdmin();
clientPageObj.clickOnClients();
clientPageObj.clickOnAddClient();
clientPageObj.clickOnName(nam);
clientPageObj.select_List(grp);
clientPageObj.enterAddress(add);
clientPageObj.select_status(st);
clientPageObj.enter_Lat(lat);
clientPageObj.enter_long(log);
clientPageObj.clickOnSubmit();
return clientPageObj;
}
}
Client:
package client;
import org.testng.Assert;
import org.testng.annotations.*;
import pageobjects.ClientPage;
import pageobjects.HomePage;
import steps.LoginSteps;
import steps.clientsteps;
import util.DriverManager;
import static util.DriverManager.driver;
public class clientTest
{
@BeforeSuite(groups = {"regression"})
public void initDriver(){
DriverManager manager = new DriverManager();
}
@AfterSuite
public void verifyValidLogintoSpree() {
LoginSteps loginSteps = new LoginSteps();
HomePage expected_message = loginSteps.Login("geosony", "1");
}
@Test
public void verifyValidLoginWithDataProvider()
{
clientsteps log= new clientsteps();
ClientPage ex = log.Login("guru99","Test Group","ekm","active","1","2");
Assert.assertTrue(driver.getPageSource().contains("Hello Sony George"));
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Regression">
<parameter name="userName" value="geosony"/>
<parameter name="password" value="1"/>
<test name="regression">
<groups>
<run>
<include name="regression"/>
<exclude name="sanity"/>
</run>
</groups>
<classes>
<class name="login.loginTest"/>
<class name="client.clientTest"/>
</classes>
</test>
</suite>
Console Error:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -ea
-Didea.launcher.port=7536
-Didea.launcher.bin.path=/home/naveen/idea-IC-162.2228.15/bin
-Didea.testng.sm_runner
-Dfile.encoding=UTF-8
-classpath /home/naveen/idea-IC-162.2228.15/lib/idea_rt.jar:
/home/naveen/idea-IC-162.2228.15/plugins/testng/lib/testng-plugin.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/cldrdata.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/dnsns.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/icedtea-sound.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jaccess.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/localedata.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/nashorn.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunec.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunjce_provider.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunpkcs11.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/zipfs.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/management-agent.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:
/home/naveen/IdeaProjects/QberTestCase/target/test-classes;
/home/naveen/IdeaProjects/QberTestCase/target/classes;
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-java/3.0.1/selenium-java-3.0.1.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-chrome-driver/3.0.1/selenium-chrome-driver-3.0.1.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-remote-driver/3.0.1/selenium-remote-driver-3.0.1.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-api/3.0.1/selenium-api-3.0.1.jar:
/home/naveen/.m2/repository/cglib/cglib-nodep/3.2.4/cglib-nodep-3.2.4.jar:
/home/naveen/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar:
/home/naveen/.m2/repository/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar:
/home/naveen/.m2/repository/com/google/guava/guava/19.0/guava-19.0.jar:
/home/naveen/.m2/repository/net/java/dev/jna/jna-platform/4.1.0/jna-platform-4.1.0.jar:
/home/naveen/.m2/repository/net/java/dev/jna/jna/4.1.0/jna-4.1.0.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-edge-driver/3.0.1/selenium-edge-driver-3.0.1.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-firefox-driver/3.0.1/selenium-firefox-driver-3.0.1.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-ie-driver/3.0.1/selenium-ie-driver-3.0.1.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-opera-driver/3.0.1/selenium-opera-driver-3.0.1.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-safari-driver/3.0.1/selenium-safari-driver-3.0.1.jar:
/home/naveen/.m2/repository/io/netty/netty/3.5.7.Final/netty-3.5.7.Final.jar:
/home/naveen/.m2/repository/org/seleniumhq/selenium/selenium-support/3.0.1/selenium-support-3.0.1.jar:
/home/naveen/.m2/repository/junit/junit/4.12/junit-4.12.jar:
/home/naveen/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:
/home/naveen/.m2/repository/net/sourceforge/htmlunit/htmlunit/2.23/htmlunit-2.23.jar:
/home/naveen/.m2/repository/xalan/xalan/2.7.2/xalan-2.7.2.jar:
/home/naveen/.m2/repository/xalan/serializer/2.7.2/serializer-2.7.2.jar:
/home/naveen/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar:
/home/naveen/.m2/repository/org/apache/httpcomponents/httpclient/4.5.2/httpclient-4.5.2.jar:
/home/naveen/.m2/repository/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4.jar:
/home/naveen/.m2/repository/org/apache/httpcomponents/httpmime/4.5.2/httpmime-4.5.2.jar:
/home/naveen/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:
/home/naveen/.m2/repository/net/sourceforge/htmlunit/htmlunit-core-js/2.23/htmlunit-core-js-2.23.jar:
/home/naveen/.m2/repository/net/sourceforge/htmlunit/neko-htmlunit/2.23/neko-htmlunit-2.23.jar:
/home/naveen/.m2/repository/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar:
/home/naveen/.m2/repository/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar:
/home/naveen/.m2/repository/net/sourceforge/cssparser/cssparser/0.9.20/cssparser-0.9.20.jar:
/home/naveen/.m2/repository/org/w3c/css/sac/1.3/sac-1.3.jar:
/home/naveen/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar:
/home/naveen/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:
/home/naveen/.m2/repository/com/codeborne/phantomjsdriver/1.3.0/phantomjsdriver-1.3.0.jar:
/home/naveen/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.2.15.v20160210/websocket-client-9.2.15.v20160210.jar:
/home/naveen/.m2/repository/org/eclipse/jetty/jetty-util/9.2.15.v20160210/jetty-util-9.2.15.v20160210.jar:
/home/naveen/.m2/repository/org/eclipse/jetty/jetty-io/9.2.15.v20160210/jetty-io-9.2.15.v20160210.jar:
/home/naveen/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.2.15.v20160210/websocket-common-9.2.15.v20160210.jar:
/home/naveen/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.2.15.v20160210/websocket-api-9.2.15.v20160210.jar:
/home/naveen/.m2/repository/org/testng/testng/6.9.13.6/testng-6.9.13.6.jar:
/home/naveen/.m2/repository/org/apache/ant/ant/1.9.7/ant-1.9.7.jar:
/home/naveen/.m2/repository/org/apache/ant/ant-launcher/1.9.7/ant-launcher-1.9.7.jar:
/home/naveen/.m2/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar:
/home/naveen/.m2/repository/com/beust/jcommander/1.48/jcommander-1.48.jar:
/home/naveen/idea-IC-162.2228.15/plugins/testng/lib/jcommander.jar
com.intellij.rt.execution.application.AppMain
org.testng.RemoteTestNGStarter -port 45387 -usedefaultlisteners false
-socket41582 @w@/tmp/idea_working_dirs_testng.tmp -temp /tmp/idea_testng.tmp [TestNG] Running:
/home/naveen/.IdeaIC2016.2/system/temp-testng-customsuite.xml Dec 02,
2016 11:20:18 AM org.openqa.selenium.remote.ProtocolHandshake
createSession INFO: Attempting bi-dialect session, assuming Postel's
Law holds true on the remote end Dec 02, 2016 11:20:18 AM
org.openqa.selenium.remote.ProtocolHandshake createSession INFO:
Detected dialect: OSS org.openqa.selenium.NoSuchElementException:
Unable to locate element: {"method":"link text","selector":"Admin"}
Command duration or timeout: 73 milliseconds For documentation on this
error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info:
version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13
-0700' System info: host: 'naveen-Inspiron-3542', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic',
java.version: '1.8.0_111' Driver info:
org.openqa.selenium.firefox.FirefoxDriver Capabilities
[{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true,
databaseEnabled=true, version=45.0, platform=LINUX,
nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true,
locationContextEnabled=true, browserName=firefox,
takesScreenshot=true, javascriptEnabled=true,
cssSelectorsEnabled=true}] Session ID:
9912e0b3-f2fe-4c4e-b85c-b91c97016e2c
*** Element info: {Using=link text, value=Admin} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:425)
at org.openqa.selenium.By$ByLinkText.findElement(By.java:246) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy6.click(Unknown Source) at pageobjects.ClientPage.clickOnAdmin(ClientPage.java:37) at steps.clientsteps.Valid(clientsteps.java:14)
at client.clientTest.verifyValidLoginWithDataProvider(clientTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1137) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:753) at org.testng.TestRunner.run(TestRunner.java:607) at org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:363) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:321) at org.testng.SuiteRunner.run(SuiteRunner.java:270)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284) at org.testng.TestNG.runSuitesLocally(TestNG.java:1209) at org.testng.TestNG.runSuites(TestNG.java:1124)
at org.testng.TestNG.run(TestNG.java:1096) at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to
locate element: {"method":"link text","selector":"Admin"} For
documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html Build info:
version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13
-0700' System info: host: 'naveen-Inspiron-3542', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic',
java.version: '1.8.0_111' Driver info: driver.version: unknown at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///tmp/anonymous2341135334492972632webdriver-profile/extensions/[email protected]/components/driver-component.js:11187)
at <anonymous class>.FirefoxDriver.prototype.findElement(file:///tmp/anonymous2341135334492972632webdriver-profile/extensions/[email protected]/components/driver-component.js:11196)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///tmp/anonymous2341135334492972632webdriver-profile/extensions/[email protected]/components/command-processor.js:12705)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///tmp/anonymous2341135334492972632webdriver-profile/extensions/[email protected]/components/command-processor.js:12710)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///tmp/anonymous2341135334492972632webdriver-profile/extensions/[email protected]/components/command-processor.js:12652)
=============================================== Default Suite Total tests run: 1, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0