When I am trying run a simple selenium webdriver Application, then the following error occurs - selenium

public class FirstTest
{
public static void main(String[] args)
{
WebDriver driver =new FirefoxDriver();
driver.get("https://www.google.co.in/");
driver.close();
}
}
Note: Webdriver Java Language Bindings 3.3.1
**Error:**
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions#3c6f6d, version=, platform=ANY, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile#1eb8acf}], required capabilities = Capabilities [{}]
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'RAJANIKANT', ip: '192.168.0.102', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:293)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:272)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:267)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:263)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:122)
at FirstTest.main(FirstTest.java:15)

If you are using WebDriver 3.3 or higher then you have to download the gecko driver .
This is the link to download the latest geckodriver.exe : Click here to download geckodriver
and then set system properties.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gecko {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", **path to your geckodriver.exe**");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.google.co.in/");
driver.close();
}
}

Related

While launching the Chrome driver I am getting "Session not created from timeout"

My error is:org.openqa.selenium.SessionNotCreatedException: session
not created from timeout: Timed out receiving message from renderer:
600.000 (Session info: chrome=79.0.3945.130) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System
info: host: 'swati-*con-Mac', ip: 'fe80:0:0:0:10ea:7ed8:242:224c%en0',
os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6',
java.version: '12.0.2' Driver info: driver.version: ChromeDriver
remote
Code I a am using is:
public static void initialization(){
String browserName = prop.getProperty("browser");
if(browserName.equals("chrome")){
System.setProperty("webdriver.chrome.driver", "/Users/swati/Drivers/chromedriver");
driver = new ChromeDriver();
}
else if(browserName.equals("FF")){
System.setProperty("webdriver.gecko.driver", "/Users/swati/Drivers/geckodriver");
driver = new FirefoxDriver();
}
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);
// Create a wait. All test classes use this.
wait = new WebDriverWait(driver, 15);
// Instantiate the Page Class
page = new PageGenerator(driver);
//driver.get(prop.getProperty("url"));
option 1:Change path till chrome.exe
System.setProperty("webdriver.chrome.driver", "/Users/swati/Drivers/chromedriver/chrome.exe");
Option 2:
Use latest chrome driver version compatible with your chrome browser.
Option 3
Refer old posts this might help you
org.openqa.selenium.SessionNotCreatedException: session not created exception
try this?
public static void main(String[] args) throws InterruptedException, AWTException {
//Initialize ChromeDriver Instance.
System.setProperty("webdriver.chrome.driver", "C:\\RPCPMAutomation\\WebDrivers\\chromedriver.exe");
"C:\RPCPMAutomation\WebDrivers\chromedriver.exe" - change this to your Chrome driver path.

Is InvalidArgumentException ensureCleanSession a known IEDriverServer 3.12.0 issue or am I instantiating it incorrectly?

When I attempt to instantiate IEDriverServer 3.12.0 like this:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class StartInternetExplorer {
public static void main(String[] args) {
// Add to Windows PATH variable: C:\IEDriverServer_Win32_3.12.0\;
String executable = "C:\\IEDriverServer_Win32_3.12.0\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", executable);
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com");
driver.quit();
}
}
I see this exception stack trace:
Started InternetExplorerDriver server (32-bit)
3.12.0.0
Listening on port 46039
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: All firstMatch elements failed validation
Invalid capabilities in firstMatch element 0: unknown capability named ensureCleanSession
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'XXXXXXXX', ip: '127.0.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver
remote stacktrace:
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.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(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
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:545)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:223)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:215)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:152)
at app.StartInternetExplorer.main(StartInternetExplorer.java:11)
I don't know where the "ensureCleanSession" argument is coming from, so I don't know if this means there is a bug in 3.12.0 or if I am not instantiating IEDriverServer properly.
Tried passing 4 slashes in URL and it worked. Seems they have make some changes in selenium API but I am not sure. This worked for me:
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Money {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
InternetExplorerDriver driver=new InternetExplorerDriver();
driver.get("https:\\\\www.google.com");
}
}
I cannot replicate this in release 3.14.0 - The solution was to wait for a new release.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class StartInternetExplorer {
public static void main(String[] args) {
// Add to Windows PATH variable: C:\IEDriverServer_Win32_3.14.0\;
String executable = "C:\\IEDriverServer_Win32_3.14.0\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", executable);
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com");
driver.quit();
}
}

Program not executing fine- Selenium

I downloaded Selenium 2.53 version, now I have Selenium 3.2 version, both times same blank page opened, no URL . pls chk below error message.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AadminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("WebDriver.gecko.driver","C:/geckoDriver.exe");
WebDriver driver= new FirefoxDriver();
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("Kawal");`
}
}
Build info: version: 'unknown', revision: '8c03df6', time: '2017-03-02 09:30:17 -0800'
System info: host: 'DESKTOP-BTAFHIV', ip: '192.168.153.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:293)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:272)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:267)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:263)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:122)
at abcd.AadminLogin.main(AadminLogin.java:12)
You need to change :
System.setProperty("WebDriver.gecko.driver","C:/geckoDriver.exe");
To :
System.setProperty("webdriver.gecko.driver","C:/geckodriver.exe");
In Selenium 3.x the Key-Value pair is expressed as webdriver.gecko.driver and C:/geckoDriver.exe
Try with updating code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AadminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:/geckodriver.exe"); //Here changes are made
WebDriver driver= new FirefoxDriver();
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("Kawal");`
}
}
All other things are fine. it is just some casing issue in setProperty(). And for 2.53 there is no need of geckodriver

"UnreachableBrowserException" and "UnixUtils may not be used on Windows exception" after driver.quit while using MarionetteDriver

Environment- Firefox 48.0.2 and Selenium 3.0.0-beta2 versions ,i am getting below error -
1472824777259 Marionette INFO Listening on port 61096 [Child 5848]
WARNING: pipe error: 109: file
c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc,
line 343
[Child 4048] ###!!! ABORT: Aborting on channel error.: file
c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp,
line 2046 Exception in thread "main"
org.openqa.selenium.remote.UnreachableBrowserException: Error
communicating with the remote browser. It may have died. Build info:
version: '3.0.0-beta2', revision: '2aa21c1', time: '2016-08-02
15:03:28 -0700' System info: host: 'VM7-JDB-068', ip: '10.60.88.67',
os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1',
java.version: '1.8.0_51' Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false,
marionette=true, appBuildId=20160823121617, version=, platform=XP,
proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false,
browserVersion=48.0.2, platformVersion=6.1,
XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox,
takesScreenshot=true, takesElementScreenshot=true,
platformName=Windows_NT, device=desktop}] Session ID:
499ab4bb-406d-4252-8b5d-808b22831595 at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:670)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:706)
at
org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:531)
at firefox_java.sample.main(sample.java:19) Caused by:
java.lang.IllegalStateException: UnixUtils may not be used on Windows
at
org.openqa.selenium.os.ProcessUtils.getProcessId(ProcessUtils.java:188)
at
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.getPID(UnixProcess.java:222)
at
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$300(UnixProcess.java:201)
at org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:132)
at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:155)
at
org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:196)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:94)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:649)
... 3 more on driver.quit();
Here is my Java code:
String marionetteDriverLocation = "\\Lib\\geckodriver.exe";
System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in");
driver.quit();
Could you please help .
Thanks
Below is the working copy that I just now tried. If it doesn't work, then there should be problem with selenium jar or gecodriver.exe you are using.
public class MarrionateTest {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "/BrowserDrivers/geckodriver.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(cap);
driver.get("http://www.seleniumhq.org");
driver.close();
}
}
You have used MarionetteDriver but initializing FirefoxDriver().
Please try with WebDriver driver = new MarionetteDriver(cap); it should work.

Unable to enter ID in twitter

I'm running the below selenium code.
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
public class twitter {
public static void main(String[] args) throws InterruptedException {
FirefoxDriver fd = new FirefoxDriver();
fd.get("https://twitter.com/?lang=en");
Thread.sleep(2000L);
fd.findElement(By.xpath(".//*[#id='signin-email']")).sendKeys("Hello");
}
}
But i'm getting the below error.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 14 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'U0138039-TPL-A', ip: '192.168.1.14', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_67'
Session ID: 96e0f5be-8e7d-402d-b7d0-2ebadc745663
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=40.0.3}]
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:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:273)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:94)
at twitter.main(twitter.java:10)
Caused by: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'U0138039-TPL-A', ip: '192.168.1.14', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_67'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.visible(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:9982)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12626)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12643)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12648)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12590)
please let me know how can i fix it.
Thaks
The problem I ran into is when I navigated to the site myself, the login panel was showing but when I did the same thing with code, the login panel was not showing. The way to get around that is to click on the "Log In" button, then enter the username/password. The code below clicks the Log In button and enters the email and password
driver.get("https://twitter.com/?lang=en");
driver.findElement(By.cssSelector("button.StreamsLogin")).click();
driver.findElement(By.id("signin-email")).sendKeys("email");
driver.findElement(By.id("signin-password")).sendKeys("password");
EDIT: For those who can't see the Log In button??? This is what I see.
I tried with JavascriptExecutor as below and it worked! It fills user name and password as foo and bar and submits.
package org;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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;
public class TwitterTest {
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// driver.manage().window().maximize();
// Go to the page
driver.get("https://twitter.com/?lang=en");
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[#class='front-signin js-front-signin']")));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('signin-email').value = 'foo';");
js.executeScript("document.getElementById('signin-password').value = 'bar';");
js.executeScript("document.getElementsByClassName('t1-form signin')[0].submit();");
wait.wait(10);
driver.quit(); }
}