Selenium tests are failing due to org.openqa.selenium.NoSuchSessionException: invalid session id on two different machine - selenium

org.openqa.selenium.NoSuchSessionException: invalid session id
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:25:02.294Z'
System info: host: 'chaos', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-957.21.3.el7.x86_64', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 83.0.4103.106, chrome: {chromedriverVersion: 83.0.4103.39 (ccbf011cb2d2b..., userDataDir: /tmp/.com.google.Chrome.XiR2sj}, goog:chromeOptions: {debuggerAddress: localhost:37450}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: cf2b9146e49c20dccbba70b575b2a393
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
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 com.tomtom.workflow.iris.uitest.pages.LoginService.logout(LoginService.java:66)
This problem is coming while loggingin and logged out into the application.
I have verified the chrome version/browser compatibility as well.
Some tome tests are running well and some time multiple tests ae getting failed due to this reason.
Options I have tried:
checked Chrome driver compatibility:
browserVersion: 83.0.4103.106,chromedriverVersion: 83.0.4103.39
I have also checked the test;there is no use of driver.quit() and
driver.close()
Selenium server version is "3.141.59".
JDK version is "1.8".
Problem is coming in executing the below code:
public void logout(String url) throws URISyntaxException {
// when user is logged out
URIBuilder uri = new URIBuilder(url);
uri.setPath("uiris/logout");
**$.driver().get().get(uri.toString());** //this line is causing the
issue.
$("*[id='login.signIn']").waitUntil(5000).isPresent();
LOG.info("log out is done successfully.");
}
I am not able to understand what is the issue.
The issue is not reproduced, if the tests are run on the local machine. But
when tests are running on two different Jenkins created machines in
parallel, then multiple tests are getting failed due to this problem only on
one machine.
Iam not able to identitify,if theerei somethng wrong with the machne on which tests are running or there is some issue withn the chrome driver.
Anybody can help me with this?

The issue is that both machines are using the same chrome session

Related

Not able to run selenium test jar in ec2

I am new to selenium and by help of some blogs and videos and i made a java selenium test in eclipse which is running perfectly fine, but my goal is to run the file on an ec2. I exported the jar and tried to run it on a ubuntu VM, but it is not running and giving the error as mentioned below. Any help would be appreciated.
Microsoft Edge WebDriver was started successfully.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: chrome not reachable
Host info: host: 'ip-192-168-2-75', ip: '192.168.2.75'
Build info: version: '4.7.1', revision: 'c6795baf1a3'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-1027-aws', java.version: '11.0.17'
Driver info: org.openqa.selenium.edge.EdgeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: MicrosoftEdge, ms:edgeOptions: {args: [], extensions: []}}], desiredCapabilities=Capabilities {browserName: MicrosoftEdge, ms:edgeOptions: {args: [], extensions: []}}}]
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:551)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:159)
at org.openqa.selenium.chromium.ChromiumDriver.(ChromiumDriver.java:101)
at org.openqa.selenium.edge.EdgeDriver.(EdgeDriver.java:54)
at org.openqa.selenium.edge.EdgeDriver.(EdgeDriver.java:46)
at org.openqa.selenium.edge.EdgeDriver.(EdgeDriver.java:42)
at ui.SureSMSTest.main(SureSMSTest.java:36)

Not able to do Sendkeys() in Username box. It shows Elementnotinteractable Exception using Selenium Webdriver

In Registration Form, Trying to enter text in username text box using sendkeys(). But it throws ElementNotInteractable Exception. Then i used implicit wait and webdriverwait to find that element , it also throwed be Timeout Exception. Kindly suggest a solutions for this, as i am not able to proceed for here. Used selenium Webdriver with java.
here is the site used
Attached the DOM tree image
Code Below:
#Test
public void regform() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
RemoteWebDriver d = new ChromeDriver();
d.manage().window().maximize();
d.get("http://way2automation.com/way2auto_jquery/index.php");
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(d, 20);
WebElement usrname = d.findElementByXPath("//input[#name='username']");
wait.until(ExpectedConditions.visibilityOf(usrname));
usrname.sendKeys("User1");
d.close();
}
Console Log:
FAILED: regform
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of [[ChromeDriver: chrome on WINDOWS (12e645803db8e870be7722d06896cc88)] -> xpath: //input[#name='username']] (tried for 20 second(s) with 500 milliseconds interval)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-O0V8JPK', ip: '192.168.1.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 81.0.4044.138, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: C:\Users\Shamili\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:61086}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 12e645803db8e870be7722d06896cc88
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at basicautomationconcepts.RegistrationForm.regform(RegistrationForm.java:24)
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:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
The page you try to automate contains two similar forms, hence there are two elements within the DOM that match your XPath. The first one is not displayed and thus not interactable. That is why you got ElementNotInteractableException, and that is why you get TimeoutException trying to wait until it became visible.
Changing your xpath to "(//input[#name='username'])[2]" should solve the problem.
You can also try with the below xpath. It worked for me.
"//*[#id=\"load_form\"]/fieldset[6]/input"

Hover is not working in selenium test for Windows 8.1 and Firefox 60.4 combination

Hover is not working in selenium test for Windows 8.1 and Firefox 60.4 combination code is right its working fine with linux OS with same firefox version
I have tried it with Linux with same firefox version
System info: host: 'PWDCSV-W81N14', ip: '10.232.247.174', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 60.4.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.26.0, moz:headless: false, moz:processID: 11060, moz:profile: C:\Temp\rust_mozprofileHY1rIp, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 6.3, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
this is the error logs
Caused by: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for com.ptc.selenium.SolventSelenium$9#67b174b9 (tried for 180 second(s) with 500 milliseconds interval)with build info as above

org.openqa.selenium.ElementNotInteractableException: Element <a class="bg-inverse "> could not be scrolled into view when trying to click a button

I'm working with gecko driver selenium java with FF 60.0. Previously my code was working properly, but all of sudden, now every time I run it, it gives me an error as could not be scrolled into view while I'm trying to click a button.
below is my code, I tried with Thread.sleep(5000) or implicit wait but nothing is working.I'm stuck here.
public void goToWorkerSummary() throws InterruptedException {
WebElement btnWorkerSummary = driver.findElement(By.xpath("//a[#href='/admin/worker-summary']"));
//Thread.sleep(5000);//wait.until(ExpectedConditions.visibilityOf(btnWorkerSummary).click();
btnWorkerSummary.click();
}
the Code up to this points works but as soon as it reaches here, it is showing the above error.
below is the error snippet.
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <a class="bg-inverse text-white dropdown-item" href="/admin/worker-summary"> could not be scrolled into view
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z'
System info: host: 'CPU-38', ip: '192.168.0.55', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 60.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 2480, moz:profile: C:\Users\xyz\AppData\Lo..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 6.2, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 08c08933-06f6-480c-88c9-9d7ab718c2c8
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
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.RemoteWebElement.execute(RemoteWebElement.java:276)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
This error message...
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <a class="bg-inverse text-white dropdown-item" href="/admin/worker-summary"> could not be scrolled into view
...implies that the GeckoDriver / FirefoxDriver was unable to interact with the desired element.
Solution
Once you locate the element btnWorkerSummary moving ahead as you are invoking click() instead of ExpectedConditions as visibilityOf you need to use elementToBeClickable() as follows:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#href='/admin/worker-summary']"))).click();
However, another issue is the incompatibility between the version of the binaries you are using as follows:
Your Selenium Client version is 3.12.0.
Your JDK version is 1.8.0_51 which is ancient.
Solution
Upgrade JDK to recent levels JDK 8u201.
Execute your #Test.
Try to use javascriptexecutor as shown sample code below,
JavascriptExecutor je = (JavascriptExecutor) driver;
je.executeScript("arguments[0].scrollIntoView(true);",driver.findElement(By.xpath("//a[#href='/admin/worker-summary']")));
You can simply try following js to scroll the page.Enter Pixel asper your requirement to scroll page. Here I use 3000 Px to scroll page to mid
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,3000)");

"cannot focus element" exception while trying to upload an attachment using selenium

While trying to upload an attachment, trying to send the keys instead of opening the OS based file explorer window as sending the path to the file would be easy.
Tried with different element identifiers, still not able to send the keys. mentioned the element HTML below.
Attached the image of element.
Tried Below Xpath,
//*[#id='fileListVideo']//*[starts-with(#class,'qq-upload-button')]
Error Log:
org.openqa.selenium.WebDriverException: unknown error: cannot focus element
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.39.562713 (dd642283e958a93ebf6891600db055f1f1b4f3b2),platform=Mac OS X 10.13.4 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'nagarjunaMBP.local', ip: 'fe80:0:0:0:c2e:b816:67ae:922b%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.39.562713 (dd642283e958a9..., userDataDir: /var/folders/g4/dylg4g7s7wb...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 66.0.3359.181, webStorageEnabled: true}
Session ID: 38b991ebd4acf37fd0aefaef902853f9
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:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
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.RemoteWebElement.execute(RemoteWebElement.java:276)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100)
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.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
at com.sun.proxy.$Proxy17.sendKeys(Unknown Source)
at actions.PublishBroadcast.MediaLibAction.uploadVideos(MediaLibAction.java:76)
at stepDefinitions.Publish.SDMediaLibrary.Upload_an_Image(SDMediaLibrary.java:43)
at ✽.When Upload an Image(features/publish/mediaLibrary/MediaLibrary.feature:10)
If you are trying to upload a file, and the page uses the standard upload mechanisms provided by HTML, you can do this directly with Selenium itself. The standard HTML mechanism is with an <input type=‘file’> element. Once you’ve found that file upload element on the page, you can use element.sendKeys(“full/path/and/file/name/here”);
where element would be :
WebElement element = driver.findElement(By.cssSelector(input[type='file']));
I was trying with the path to div which will not accept the values. So changes the path to input value //*[#id='fileList']//*[#type='file'] or //*[#id='fileList']//input[#type='file'] this worked.
Thanks to #Andersson