Test case not running iin selenium webdriver - selenium-webdriver

I tried to use the following code to open a URL in my local system. But I get error message as shown in screen shot.
Code
package First_test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class first_case {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//Launch the Website
driver.get("http://127.0.0.1:3000");
// Print a Log In message to the screen
System.out.println("Successfully opened the website ");
// Close the driver
driver.quit();
}
}
error message
What shall I do to solve this problem? Thanx!

You need to install gecko driver. A brief introduction about it and how to install gecko driver can be found in following link. Hope this helps!
Gecko Driver is the link between your tests in Selenium and the Firefox browser
http://toolsqa.com/selenium-webdriver/how-to-use-geckodriver/

I installed gecko driver from github and put it in the folder location of my workplace and it worked!
working result

Download geckodriver and use this code:
System.setProperty("webdriver.gecko.driver", "E:/software and tools/geckodriver.exe");
WebDriver driver= new ChromeDriver();
//Launch the Website
driver.get("http://127.0.0.1:3000");
// Print a Log In message to the screen
System.out.println("Successfully opened the website ");
// Close the driver
driver.quit();

Related

IE driver 4.0.0 stuck at This is the initial start page for the WebDriver server

I am using Internet Explorer driver 4.0.0(32bit) and selenium updated version 4.1.2when I run the code using Internet Explorer driver 4.0.0 it is stuck at This is the initial start page for the WebDriver server.
even though I check the setting in Internet Explorer:
All the protected mode is disabled
zoom setting is 100% for Internet Explorer and windows also
enchanted protected mode is off
but when I change the Internet Explorer driver to 3.1.4 it works fine. I also tried the Internet Explorer 4.0.0 for 64 but the same issue I am facing please help me.
public class EdgeTest {
static RemoteWebDriver driver = null;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.ie.driver",
"D:\\Automation\\Jar Details\\Drivers\\IEDriverServer_Win32_4.0.0\\IEDriverServer.exe");
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
ieOptions.setCapability("ignoreProtectedModeSettings", true);
ieOptions.setCapability("ignoreZoomSettings",true);
System.out.println("this:"+ieOptions.getCapability("ignoreZoomSettings"));
driver = new InternetExplorerDriver(ieOptions);
InternetExplorerDriverService.createDefaultService();
driver.get("https://github.com/");
WebElement elem = driver.findElement(By.name("q"));
elem.sendKeys("gitu");
elem.sendKeys(Keys.ENTER);
driver.quit();
error: "Could not create a new remote session" this is an error
getting
It looks like you are using selenium webdriver to automate Edge IE mode. I tried executing your code and I found this code to work fine (using IE driver 4.0.0 and Selenium 4.1.2).
But when executing code again before the code has not been executed complete, you get the same problem you describe (execute code twice at once). like this:
So I think when the IE driver may be occupied, you can try to open the task manager, end the related task (IE driver 32 bit), and then re-execute the code, I think this should be useful to you.

Unable to connect a Run A Script in Selenium using IE Driver

Trying to Run a Script in Luna Eclipse using IE Driver
and getting the following error:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Here is the code trying to Run:
package com.newpack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SecondClass {
public static void main(String[] args)
{
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("requireWindowFocus", true);
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,"https://www.google.co.in");
System.setProperty("webdriver.ie.driver","M:\\workspace\\IEDriver.exe");
WebDriver driver ;
driver = new InternetExplorerDriver(capabilities);
String baseUrl = "https://www.google.co.in";
driver.get(baseUrl);
String expectedTitle = "Google";
String actualTitle = "";
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
driver.close();
System.exit(0);
}
}
try once following steps
Got to
internet options>>Security>>
click on:"Reset all zones to default level"
ensure that the 'Enable protected mode' checkbox is ticked for all the four zones. Like i.e Internet, Local internet, Trusted Sites, Restricted Sites.
Internet Explorer needs to be configured first in order to successfully run a selenium script.
Make sure you complete all the following steps:
Go to Internet Options > Security and enable "Protected Mode" for all the 4 zones: Internet, Local internet, Trusted Sites, Restricted Sites.
Also, click on Custom Level for all 4 zones and reset Recent Custom Settings to same level, say "Medium" or "High".
If this does not work, please update your IEDriverServer from Selenium Official Downloads

Unable to launch Firefox browser from Selenium Webdriver version 3.4.0

I am facing an issue wherein I am unable to launch firefox from Selenium Webdriver version 3.4.0 from my Windows operating system (Windows 7) which is 64 bit.
Currently, firefox version 52.0.2 is installed on my machine.
I have also added selenium jar files to the library, still it is showing error.
My code:
package sanity;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login
{
public static void main(String[] args)
{
WebDriver driver=new FirefoxDriver();
driver.close();
}
}
Error:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
at sanity.Login.main(Login.java:18)
After this, I downloaded GeckoDriverService form SeleniumHQ.org and ran below code, now after running below updated code with the Geckodriver path, firefox browser is getting launched but not closing automatically. Also I am getting some message in console.
Code:
package sanity;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login
{
public static void main(String[] args)
{
String Firefoxdriverpath="C://Users//Ashish//Downloads//geckodriver-v0.16.0-win64//geckodriver.exe";
System.setProperty("webdriver.gecko.driver", Firefoxdriverpath);
WebDriver driver=new FirefoxDriver();
driver.close();
}
}
Console:
1492944489305 geckodriver INFO Listening on 127.0.0.1:12059
1492944489973 geckodriver::marionette INFO Starting browser \\?\C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1492944491445 addons.manager ERROR startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70" data: no] Stack trace: FileUtils_getDir()#resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()#resource://gre/modules/FileUtils.jsm:42 < AddonManagerInternal.validateBlocklist()#resource://gre/modules/AddonManager.jsm:700 < AddonManagerInternal.startup()#resource://gre/modules/AddonManager.jsm:870 < this.AddonManagerPrivate.startup()#resource://gre/modules/AddonManager.jsm:3033 < amManager.prototype.observe()#resource://gre/components/addonManager.js:65
JavaScript error: resource://gre/modules/AddonManager.jsm, line 1677: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1492944492505 Marionette INFO Listening on port 50231
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2585: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
Apr 23, 2017 4:18:14 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Kindly help.
Thanks,
Ashish Jain
Please, try it again using "driver.quit" instead of "driver.close".
About the "Javascript error (AddonManager)" I'm still trying to figure out how to fix it too, if someone know a way please share with us :)
Can you please try the below code,
String Firefoxdriverpath="C://Users//Ashish//Downloads//geckodriver-v0.16.0-win64//geckodriver.exe";
System.setProperty("webdriver.gecko.driver", Firefoxdriverpath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.close();
Please let me know if this is working.
I had the similar issue but finally got it solved by this small code below changed for selenium 3.4 capability-
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false); // true gives that Javascript error (AddonManager is not initialized)
What is your Firefox version??
sometimes the problem is the incompatibility between the installed FireFox version and the geckodriver version
About the "Javascript error (AddonManager)"... I almost went nuts today trying to fix this, since all the components were installed gradually within the last week.In the end I solved it.
Here's the solution and the explanation:
geckodriver v.0.16.0 "is only compatible with Selenium 3.4 and greater" (as it says on their page).
A week ago selenium 3.3.1 was the last version. As of April 21, selenium3.4.0 was released.
I had to recreate the project from scratch, re-adding the Selenium jars. For some reason simply replacing them on the old project, didn't do the trick.
I don't see any significant error in your code as such. But you need to follow certain guidelines as follows:
While declaring String Firefoxdriverpath either you need to use single front slashes i.e "/"
e.g. String Firefoxdriverpath="C:/Utility/BrowserDrivers/geckodriver.exe";
OR you need to escape the back slashes i.e "\\"
e.g. String Firefoxdriverpath="C:\\Utility\\BrowserDrivers\\geckodriver.exe";
Let me know if this works for you.
I had the same issue.
What helps is usage of driver.quit(); instead of driver.close();
Got this error when using Firefox version: 45.9.0; Selenium 3.4.0 and Gecko driver: 16.1.
Solution: Downgrade to gecko 16.0 and use:
System.setProperty("webdriver.firefox.marionette", "Path");
Hope this helps.

Unable to open chrome using Selenium

I am using the following code to run chrome driver:
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestClass
{
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", "/Users/raisa/Documents/Selenium/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.quit();
}
}
But I am getting this error:
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /Users/raisa/Documents/Selenium/chromedriver.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:117)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:112)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
at TestClass.main(TestClass.java:11)
I have downloaded the latest chrome driver from http://chromedriver.storage.googleapis.com/index.html
I agree with the comments.
On Mac OS you will not need .exe after chromedriver.
For your example you'll want it to look like this: /Users/raisa/Documents/Selenium/chromedriver.
I've also seen this problem come up because the execute permissions wasn't set for the file.
So double check the file permissions, and also that the file is in the actual path given.
Through terminal navigate to the place where chromedriver is located and then execute following command.
xattr -d com.apple.quarantine chromedriver

Unable to launch Firefox driver

I have Firefox 11 in my Win7 system with selenium 24.1:
When I tried to launch Firefox using from Eclipse, I got following error(It's same for all even after re installation ):
**Exception in thread "main" java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:389)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:89)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.fire fox.FirefoxDriver.<init>(FirefoxDriver.java:95)at mend.w.main(w.java:9)
Following is the code, I tried:
package try;
import org.openqa.selenium.firefox.FirefoxDriver;
public class trySelenium {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver n = new FirefoxDriver();
n.get("google.com");
}
}
Since you are using selenium 2.41, it will not support Firefox 11. Either upgrade your browser or downgrade selenium version to respective supported Firefox version.
Instead of using:
FirefoxDriver n = new FirefoxDriver();
use following in your code:
WebDriver n = new FirefoxDriver();
WebDriver is an interface that FirefoxDriver class is implementing.

Resources