org.openqa.selenium.SessionNotCreatedException - java

I am getting error org.openqa.selenium.SessionNotCreatedException:
once i execute the code
package SignUp;
import java.net.URL; import java.util.concurrent.TimeUnit; import
org.openqa.selenium.By; import
org.openqa.selenium.remote.DesiredCapabilities; import
org.testng.annotations.BeforeTenter code hereest; import
org.testng.annotations.Test;
import io.appium.java_client.ios.IOSDriver;
public class SignUPBaseclass { public IOSDriver driver;
#BeforeTest public void SignUp1() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("appium-version", "1.0");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "9.3");
capabilities.setCapability("deviceName", "iPhone 5S Plus");
capabilities.setCapability("app", "/Users/sumit/Desktop/Project
/FSFosh-1.ipa"); IOSDriver driver = new IOSDriver(new
URL("http://127.0.0.1:4725/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
#Test public void Flow(){ driver.findElement(By.name("JOIN US
FREE!")).click(); //AppiumCapabilities App_Cap = new
AppiumCapabilities(); //App_Cap.driver.findElement(By.name("JOIN
US FREE!")).click();
} /*#AfterClass //public void tearDown() { AppiumCapabilities App_Cap = new AppiumCapabilities(); App_Cap.driver.quit(); }*/
}
Error Message
[TestNG] Running:
/private/var/folders/6r/_2b4t0zj1tj95nkmxmj9c5n40000gp/T/testng-eclipse-2068198674/testng-customsuite.xml
log4j:WARN No appenders could be found for logger
(org.apache.http.client.protocol.RequestAddCookies). log4j:WARN
Please initialize the log4j system properly. FAILED CONFIGURATION:
#BeforeTest SignUp1 org.openqa.selenium.SessionNotCreatedException:
A new session could not be created. (Original error: Requested a new
session but one was in progress) (WARNING: The server did not
provide any stacktrace information) Command duration or timeout: 469
milliseconds Build info: version: '2.53.0', revision: '35ae25b',
time: '2016-03-15 16:57:40' System info: host:
'Appster-Sumit-Nagar.local', ip: '172.16.17.71', os.name: 'Mac OS
X', os.arch: 'x86_64', os.version: '10.11.3', java.version:
'1.7.0_80' Driver info: io.appium.java_client.ios.IOSDriver at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at
io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:158)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:109)
at io.appium.java_client.ios.IOSDriver.(IOSDriver.java:23)
at SignUp.SignUPBaseclass.SignUp1(SignUPBaseclass.java:23) 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:606) at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at
org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:648) at
org.testng.TestRunner.run(TestRunner.java:616) at
org.testng.SuiteRunner.runTest(SuiteRunner.java:359) at
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) at
org.testng.SuiteRunner.run(SuiteRunner.java:261) at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1215) at
org.testng.TestNG.runSuitesLocally(TestNG.java:1140) at
org.testng.TestNG.run(TestNG.java:1048) at
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112) at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205) at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176)
SKIPPED: Flow
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1 Configuration Failures: 1,
Skips: 0
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]:
194 ms [TestNG] Time taken by org.testng.reporters.jq.Main#be71839:
322 ms [TestNG] Time taken by
org.testng.reporters.SuiteHTMLReporter#118e0f0f: 119 ms [TestNG]
Time taken by org.testng.reporters.JUnitReportReporter#1f80ce47: 21
ms [TestNG] Time taken by org.testng.reporters.XMLReporter#3f611531:
88 ms [TestNG] Time taken by
org.testng.reporters.EmailableReporter2#582ed819: 8 msenter code
here

Issue has been resolved here ,
here i just created "RemoteWebDriver" object instead of IOSDriver ..
public class SignUPBaseclass extends Testbase {
public RemoteWebDriver driver;
#BeforeTest
public RemoteWebDriver SignUp1() throws Throwable {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.0");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "9.3");
capabilities.setCapability("deviceName", "iPhone 5S Plus");
capabilities.setCapability("app", "/Users/sumit/Desktop/Project /FSFosh-1.ipa");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);
return driver;
}

Related

selenium no such session excpetion: session <id> does not exist in IEDriverServer

I have a few selenium tests on a react application. All tests are passing for chrome and firefox without any error. However, in IE (internet explorer v11) - all tests pass, but fails at the tearDown method: -
teardown method: -
#AfterClass
public void tearDown(){
driver.close();
//driver.quit();
}
screenshot of TestNG error log: -
Browser Base Class: -
public class TestBase {
public static WebDriver driver;
public static Properties prop;
public static EventFiringWebDriver e_driver;
public static WebEventListener eventlistener;
public static ChromeDriver chrome;
public static WebDriver driverName;
public TestBase(){
try {
prop = new Properties();
FileInputStream ip = new FileInputStream("src/main/java/config/config.properties");
prop.load(ip);
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e ){
e.printStackTrace();
}
}
public static void initialization(String browser){
try {
if(browser.equals("chrome")){
System.setProperty("webdriver.chrome.driver", "C:\\Browser\\chromedriver.exe");
driver = new ChromeDriver();
}else if (browser.equals("firefox")){
System.setProperty("webdriver.gecko.driver", "C:\\Browser\\geckodriver.exe");
driver = new FirefoxDriver();
}else if(browser.equals("ie")){
System.setProperty("webdriver.ie.driver", "C:\\Browser\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability("nativeEvents", false);
ieCapabilities.setCapability("unexpectedAlertBehaviour", "accept");
ieCapabilities.setCapability("ignoreProtectedModeSettings", true);
ieCapabilities.setCapability("disable-popup-blocking", true);
ieCapabilities.setCapability("enablePersistentHover", true);
ieCapabilities.setCapability("ignoreZoomSetting", true);
driver = new InternetExplorerDriver(ieCapabilities);
}else if(browser.equals("edge")){
System.setProperty("webdriver.edge.driver", "C:\\Browser\\MicrosoftWebDriver.exe");
EdgeOptions options = new EdgeOptions();
options.setCapability("unexpectedAlertBehaviour", "accept");
driver = new EdgeDriver(options);
e_driver = new EventFiringWebDriver(driver);
//now create object of event listner handler to register it with eventfiring web driver
eventlistener = new WebEventListener();
e_driver.register(eventlistener);
driverName = driver;
driver = e_driver;
}
if(!browser.contains("edge")){
e_driver = new EventFiringWebDriver(driver);
//now create object of event listner handler to register it with eventfiring web driver
eventlistener = new WebEventListener();
e_driver.register(eventlistener);
driverName = driver;
driver = e_driver;
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);
}
driver.get(prop.getProperty("url"));
} catch (TimeoutException e){
if (driver != null)
driver.close();
//driver.quit();
e.printStackTrace();
}
catch (Exception e){
e.printStackTrace();
}
}
console error log
Starting MSEdgeDriver ... (...) on port 2440
Only local connections are allowed.
Please protect ports used by MSEdgeDriver and related test frameworks to prevent access by malicious code.
org.openqa.selenium.WebDriverException: unknown error: cannot find MSEdge binary
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: '<host>', ip: '<ip>', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: driver.version: EdgeDriver
remote stacktrace: Backtrace:
Ordinal0 [0x00007FF605E27542+1930562]
Ordinal0 [0x00007FF605D8BCC2+1293506]
Ordinal0 [0x00007FF605CF0801+657409]
Ordinal0 [0x00007FF605C60F1F+69407]
Ordinal0 [0x00007FF605C5EF02+61186]
Ordinal0 [0x00007FF605C87C9D+228509]
Ordinal0 [0x00007FF605C850EF+217327]
Ordinal0 [0x00007FF605C6702F+94255]
Ordinal0 [0x00007FF605C681EE+98798]
Ordinal0 [0x00007FF605DAA6A1+1418913]
GetHandleVerifier [0x00007FF605EE8AF9+656601]
GetHandleVerifier [0x00007FF605EE8891+655985]
GetHandleVerifier [0x00007FF605EF095C+688956]
GetHandleVerifier [0x00007FF605EE92D3+658611]
Ordinal0 [0x00007FF605DA069E+1377950]
Ordinal0 [0x00007FF605DACB46+1428294]
Ordinal0 [0x00007FF605DAB9BD+1423805]
BaseThreadInitThunk [0x00007FFF02907974+20]
RtlUserThreadStart [0x00007FFF0402A271+33]
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.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:141)
at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:130)
at com.testapp.base.TestBase.initialization(TestBase.java:73)
at com.testingapp.testcases.BusyIndicatorTest.setUp(BusyIndicatorTest.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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
driver : InternetExplorerDriver: internet explorer on WINDOWS (d8509abb-d16b-4872-bdc2-010789af308c)
Trying to find Element By : By.xpath: //div[#id='hamburger_menu']
Exception occured: org.openqa.selenium.NoSuchSessionException: session d8509abb-d16b-4872-bdc2-010789af308c does not exist
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: '<host>', ip: '<ip>', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: true, ignoreZoomSetting: true, initialBrowserUrl: http://localhost:7136/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: accept}
Session ID: <id>
What I've tried: -
initializing WebDriver driver = null in browser case class
Control Panel -> Internet Options -> Security -> Disabled "protected zone" for all four zones
ieCapabilities.setCapability("ignoreProtectedModeSettings", true); this is an alias for INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
if(driver != null) {
driver.close();
}
I've tried all these which were mentioned in other stack overflow questions, however, I end up with the same error.
Do let me know if any more info. regarding the code is required.
EDIT:
I've noticed that my instance to the new InternetExplorerDriver has been striked through
driver = new InternetExplorerDriver (ieCapabilities);
This was striked, as DesiredCapabilities have been deprecated.
Before: -
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability("ignoreProtectedModeSettings", true);
driver = new InternetExplorerDriver(ieCapabilities);
Now: -
InternetExplorerOptions IEoptions = new InternetExplorerOptions();
IEoptions.setCapability("ignoreProtectedModeSettings", true);
driver = new InternetExplorerDriver(IEoptions);
This fixed the striked-through.
When I run the IE set of tests individually i.e. without chrome, firefox & edge tests. I can see all the tests passing & no error at teardown method. I am Unable to figure out the reason!

FAILED CONFIGURATION: #BeforeMethod setup org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?

I found few similar issues here(
SessionNotFoundException: Session ID is null. Using WebDriver after calling quit()? (Selenium)
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
)
but none of them did not help me to solve my issue.
Any help or advice will be appreciated.
In my case I am using TestNG.
I have created Main Class
package base;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
public class MainClass {
public WebDriver driver;
public Properties CONFIG;
public Properties XPATH;
#BeforeSuite
public void initialization() throws IOException {
String chromeDriverLocation = System.getProperty("user.dir")+"/src/main/java/driverlocation/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromeDriverLocation);
driver = new ChromeDriver();
System.out.println("Web Driver initilization has started...");
System.out.println("In the before suite...");
CONFIG = new Properties();
String configLocation = System.getProperty("user.dir")+"/src/main/java/base/Config.properties";
FileInputStream ip = new FileInputStream(configLocation);
CONFIG.load(ip);
XPATH = new Properties();
String xpathLocation = System.getProperty("user.dir")+"/src/main/java/base/xpath.properties";
FileInputStream xpathIp = new FileInputStream(xpathLocation);
XPATH.load(xpathIp);
}
#AfterSuite
public void tearDown() {
System.out.println("Web Driver is closing...");
System.out.println("it is epic...");
driver.quit();
}
}
And I have class with test which extends Main.Class
package Test.TileSearch;
import org.testng.annotations.Test;
import base.MainClass;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.By;
import org.testng.annotations.AfterMethod;
public class Tile1City1 extends MainClass {
#BeforeMethod
public void setup() throws Exception {
driver.get(CONFIG.getProperty("urlcentura"));
driver.manage().window().maximize();
}
#AfterMethod
public void tearDown() {
driver.quit();
}
#Test
public void main1() throws Exception
driver.findElement(By.xpath().click();
driver.findElement(By.xpath().click();
driver.findElement(By.xpath().click();
if(!driver.findElements(By.partialLinkText("Tile")).isEmpty()){
System.out.println("Tile is available there");
}else{
System.out.println("Tile is not available there");
}
}
#Test
public void main1() throws Exception
driver.findElement(By.xpath().click();
driver.findElement(By.xpath().click();
driver.findElement(By.xpath().click();
if(!driver.findElements(By.partialLinkText("Tile")).isEmpty()){
System.out.println("Tile is available there");
}else{
System.out.println("Tile is not available there");
}
}
}
And here is error in console
[RemoteTestNG] detected TestNG version 6.13.1
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 11302
Only local connections are allowed.
Feb 06, 2018 8:13:19 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Web Driver initilization has started...
In the before suite...
Abaco is available there
FAILED CONFIGURATION: #BeforeMethod setup
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'EARL', ip: '192.168.1.85', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:131)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)
at Test.CenturaSearch.AbacoMontreal.setup(AbacoMontreal.java:16)
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:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:451)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:516)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.runSuites(TestNG.java:1028)
at org.testng.TestNG.run(TestNG.java:996)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
SKIPPED CONFIGURATION: #AfterMethod tearDown
PASSED: main
SKIPPED: main1
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'EARL', ip: '192.168.1.85', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:131)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)
at Test.CenturaSearch.AbacoMontreal.setup(AbacoMontreal.java:16)
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:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:451)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:516)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.runSuites(TestNG.java:1028)
at org.testng.TestNG.run(TestNG.java:996)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
Only one test is running, other always skips.
Basically the problem is that I am using static attributes for WebDriver, which shouldn't be shared between different test runs.
Anyone knows how to fix that?
It looks like you're quitting the driver in Tile1City1
#AfterMethod
public void tearDown() {
driver.quit();
}
So you open the driver in a #BeforeSuite, then quit it after one test and never re-open it. I may be misreading the code, but that appears to be what is happening.
If you want a new driver per test, you need to also open your driver each test in a #BeforeMethod.
If you want to re-use the same driver for each test, remove the code I quoted from Tile1City1
inside Driver
`public static void closeDriver() {
if (driver != null) { driver.quit(); driver = null; }
}`
and use this one in #AfterMethod
Driver.closeDriver();

TestNg Script failure inside my servlet. WebDriverException: Unable to bind to locking port within 45000 ms

Code to execute my testng xml from inside servlet:
TestListenerAdapter adp = new TestListenerAdapter();
TestNG tng = new TestNG();
List<String> suites = new ArrayList<String>();
suites.add("D:\\testng.xml");
tng.setTestSuites(suites);
tng.run();
Error Message after running above through servlet method:
[TestNG] Running:
D:\\testng.xml
===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 1
===============================================
Below is the sample test script class file using in xml file
package simpleTestng;
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.Test;
public class TestNgSample {
WebDriver d;
#BeforeClass
public void test_open_browser(){
System.setProperty("webdriver.chrome.driver", "D://Selenium//driver//firefoxdriver//firefoxdriver.exe");
d=new FirefoxDriver();
}
#Test
public void open_page(){
d.get("https://www.google.com");
String title=d.getTitle();
System.out.println("title is "+title);
}
#AfterClass
public void test_close_browser(){
d.quit();
}
}
I am getting following web-driver Exception ,if right click on class file and run as Testng test
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.8.0_66'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:92)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:71)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:80)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:77)
at simpleTestng.TestNgSample.test_open_browser(TestNgSample.java:15)
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:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
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:51)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:85)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
at org.testng.TestNG.run(TestNG.java:1030)

Unable to Execute Test Case through TestNG

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
public class TestNG {
public WebDriver driver;
#Test
public void main() throws Exception {
driver.findElement(By.id("account")).click();
driver.findElement(By.id("log")).sendKeys("********");
driver.findElement(By.id("pwd")).sendKeys("*****");
driver.findElement(By.id("login")).click();
System.out.println("Login Successfully :-)");
driver.findElement(By.id("account_logout")).click();
Thread.sleep(15000);
}
#BeforeMethod
public void beforeMethod() {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver_win32 (1)\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://store.demoqa.com/");
}
#AfterMethod
public void afterMethod() {
driver.quit();
}
}
The #BeforeMethod ran successfully and launched the specified Website, but after the website has opened, it should move towards the main functionality i.e. #BeforeMethod, but unable to move further.
Please advise me, is there something wrong with the code.
Below Error we are getting:-
[TestNG] Running:
C:\Users\gmohammad\AppData\Local\Temp\testng-eclipse--1784470156\testng-customsuite.xml
Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 6093
Only local connections are allowed.
FAILED CONFIGURATION: #AfterMethod afterMethod
java.lang.NullPointerException
at com.ghulam.TestNG.afterMethod(TestNG.java:33)
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:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:703)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
FAILED: f
java.lang.NullPointerException
at com.ghulam.TestNG.f(TestNG.java:15)
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:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter#1a18493: 24 ms
[TestNG] Time taken by org.testng.reporters.jq.Main#c0f91d: 148 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter#de4588: 39 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2#354949: 15 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter#19b622d: 123 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 21 ms
Try with the below code..
I guess this is happening due to declaring the driver again in your #BeforeMethod method making the driver object local to that method itself.
Note :- Tried executing your code, it is failing again at "driver.findElement(By.id("account_logout")).click();".. please correct this and run again, it will work.
package testcases;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestNG {
public WebDriver driver;
#Test
public void main() throws Exception {
driver.findElement(By.id("account")).click();
driver.findElement(By.id("log")).sendKeys("********");
driver.findElement(By.id("pwd")).sendKeys("*****");
driver.findElement(By.id("login")).click();
System.out.println("Login Successfully :-)");
driver.findElement(By.id("account_logout")).click();
Thread.sleep(15000);
}
#BeforeMethod
public void beforeMethod() {
System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://store.demoqa.com/");
}
#AfterMethod
public void afterMethod() {
driver.quit();
}
}

Selenium Webdriver unable to locate element from webtable

I am trying to access a webtable which is quite static and get the values from each row.
I am getting an error, the code is:
import java.util.List;
import java.util.concurrent.TimeUnit;
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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class TS1_TC2 {
WebDriver driver=null;
String btn1="html/body/form/div[1]/center/table/tbody/tr/td[1]/input";
String table="html/body/form/table/tbody/tr[2]/td/div/center/table";
#BeforeTest
public void browserCheck()
{
driver=new FirefoxDriver();
driver.get("http://demo.borland.com/gmopost/");
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
#Test
public void TS1_TC2()
{
driver.findElement(By.xpath(btn1)).click();
//html/body/form/table/tbody/tr[2]/td/div/center/table/tbody
//html/body/form/table/tbody/tr[2]/td/div/center/table
WebElement table=driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td/div/center/table"));
List<WebElement> rows=table.findElements(By.tagName("tr"));
//WebDriverWait wait = new WebDriverWait(driver, 100, 15);
System.out.println(rows.size());
for(int rownum=2;rownum<rows.size();rownum++)
{
List<WebElement> cols=rows.get(rownum).findElements(By.tagName("td"));
System.out.println(cols.size());
for(int colnum=1;colnum<cols.size();colnum++)
{
//System.out.println(cols.get(colnum).getText());
//wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("html/body/form/table/tbody/tr[2]/td/div/center/table/tbody/tr["+rownum+"]/td["+colnum+"]")));
System.out.println("html/body/form/table/tbody/tr[2]/td/div/center/table/tbody/tr["+rownum+"]/td["+colnum+"]");
System.out.println(cols.get(colnum).findElement(By.xpath("html/body/form/table/tbody/tr[2]/td/div/center/table/tbody/tr["+rownum+"]/td["+colnum+"]")).getText());
System.out.println("--");
}
System.out.println();
}
}
}
The Exception thrown is as follows:
FAILED: TS1_TC2
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"html/body/form/table/tbody/tr[2]/td/div/center/table/tbody/tr[2]/td[1]"}
Command duration or timeout: 20.08 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:55:11'
System info: host: 'Vihaan-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 15f51aea-04cd-4ea4-bdae-0bdd47312bd7
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=29.0.1}]
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:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:573)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:171)
at org.openqa.selenium.remote.RemoteWebElement.findElementByXPath(RemoteWebElement.java:244)
at org.openqa.selenium.By$ByXPath.findElement(By.java:357)
at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:167)
at TS1_TC2.TS1_TC2(TS1_TC2.java:57)
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:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
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:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
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)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"xpath","selector":"html/body/form/table/tbody/tr[2]/td/div/center/table/tbody/tr[2]/td[1]"}
Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:55:11'
System info: host: 'Vihaan-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/Vihaan/AppData/Local/Temp/anonymous7820392430389922124webdriver-profile/extensions/fxdriver#googlecode.com/components/driver_component.js:8904)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/Vihaan/AppData/Local/Temp/anonymous7820392430389922124webdriver-profile/extensions/fxdriver#googlecode.com/components/driver_component.js:396)
Kindly help , because I see the the xpath from firepath is exactly the same as the xpath fetched in the for loop.
Thanks
rajee
try using
driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td/div/center/table/tbody/tr["+rownum+"]/td["+colnum+"]")).getText()
instead of
cols.get(colnum).findElement(By.xpath("html/body/form/table/tbody/tr[2]/td/div/center/table/tbody/tr["+rownum+"]/td["+colnum+"]")).getText()
It should work.
But I dont understand why you used the above line. The following code achieves the same thing.
WebDriver driver = null;
#BeforeTest
public void browserCheck() {
driver = new FirefoxDriver();
driver.get("http://demo.borland.com/gmopost/");
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
#Test
public void TS1_TC2() {
driver.findElement(By.name("bSubmit")).click();
WebElement table = driver
.findElement(By
.xpath("//form[#name='Items']/table/tbody/tr[2]/td/div/center/table"));
List<WebElement> rows = table.findElements(By.tagName("tr"));
for (int rownum = 2; rownum < rows.size(); rownum++) {
List<WebElement> cols = rows.get(rownum).findElements(
By.tagName("td"));
for (int colnum = 1; colnum < cols.size(); colnum++) {
System.out.println(cols.get(colnum).getText());
}
System.out.println("\n");
}
}
Let me know if this helps you.

Categories

Resources