This is the my code :
public class browserLaunch{
public static void main(String[]args){
WebElement usrnTxt=driver.findElement(By.name("txtUserName"));
WebElement pswdTxt=driver.findElement(By.name("txtPassword"));
WebElement lgnBtn=driver.findElement(By.id("btnLogin"));
WebDriver driver = new ChromeDriver();
String url=dataTable.getData("General_Data", "Url");
driver.get(url);
String userName = dataTable.getData("General_Data", "Username");
String password = dataTable.getData("General_Data", "Password");
usrnTxt.sendKeys(userName);
pswdTxt.sendKeys(password);
lgnBtn.click();
}}
I am getting the below error:
Starting ChromeDriver 2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961) on port 46496
Only local connections are allowed.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
org.openqa.selenium.NoSuchElementException: no such element
(Session info: chrome=47.0.2526.106)
(Driver info: chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Windows NT 6.0 SP2 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 32 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'fa_dev_app_cts2', ip: '10.10.1.33', os.name: 'Windows Server 2008', os.arch: 'x86', os.version: '6.0', java.version: '1.7.0_25'
*** Element info: {Using=link text, value=Logout}
Session ID: 5d4102db6a73fccf3ef664877a600625
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\Sagupta\AppData\Local\Temp\18\scoped_dir22744_17027}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=47.0.2526.106, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
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:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:401)
at org.openqa.selenium.By$ByLinkText.findElement(By.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at componentgroups.CommonGroups.<init>(CommonGroups.java:13)
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 supportlibraries.DriverScript.invokeBusinessComponent(DriverScript.java:498)
at supportlibraries.DriverScript.executeTestcase(DriverScript.java:452)
at supportlibraries.DriverScript.executeTestIterations(DriverScript.java:406)
at supportlibraries.DriverScript.driveTestExecution(DriverScript.java:100)
at allocator.ParallelRunner.invokeTestScript(ParallelRunner.java:58)
at allocator.ParallelRunner.run(ParallelRunner.java:39)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I am getting the below error as soon as I am starting to execute my TestCase. This error is triggered only when I am initializing the elements with WebElement like:
WebElement usrnTxt = driver.findElement(By.name("txtUserName")).
Earlier when I initialized my element by 'By' command like:
By usrnTxt = By.name("txtUserName") it was working fine.