Firefox browser not invoking from Selenium Webdriver version 3.4.0 - selenium

So here is the issue:
Basically I'm trying to invoke Firefox browser with selenium.
package basics;
import org.openqa.selenium.WebDriver;
public class BrowserInvocation {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
// There is no import option displaying when mouse over FirefoxDriver such as **import org.openqa.selenium.firefox.FirefoxDriver;**
Console output:
Exception in thread "main" java.lang.Error: Unresolved compilation
problem:
FirefoxDriver cannot be resolved to a type at
basics.firefox.main(firefox.java:19)
I'm using latest versions of all software involve (as of May 15 2017) like firefox, java, eclipse and selenium. I have use 32 bit versions and 64 bit versions. tried removing everything and setup environment again but no luck.
I have tried invoking chrome in same environment with chrome driver and so far at least I can invoke the browser.

Related

Can selenium test run without using System.setProperty in the code?

I am able to run the selenium test in our project without using System.setProperty. Not sure how it works, we have set the environment Path variable with value "C:\Akash\Drivers" where all the drivers are stored. Can anyone explain how/ this works without setting up chrome path?
public class SeleniumTest {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
localSettings();
}
public static void localSettings() {
// System.setProperty("webdriver.chrome.driver", "C:\\Akash\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
}
}
Please Refer official explanation given Seleniumhq & Chrome,
How it retrieves and Work with Environment Variables :
WebDriver works with Chrome through the chromedriver binary. You need to have both chromedriver and a version of chrome browser installed. chromedriver needs to be placed somewhere on your system’s path in order for WebDriver to automatically discover it. The Chrome browser itself is discovered by chromedriver in the default installation path. These both can be overridden by environment variables.
Provided by Seleniumhq, Blog Link : Click Here
Chrome Driver Setup Provisions:
Provided by Chrome, Blog Link : Click Here

Cannot execute testcase exported from selenium ide as java/junit4/remote control in eclipse ide

I am new to testing and i am trying to learn how to run recorded test cases in selenium ide in eclipse.
I recorded a testcase to search word selenium in the Google.
I exported it as java/junit4/remote control
Then i strated a new project in eclipse and add "java 4.12"and "selenium stand
alone server" external jar files.
I add the exporetd code to the project.
Then i started command prompt and executed selenium stand alone server.
Then i clicked run as junit in eclipse ide.
Firefox launched but an error is occured.
below is the code i executed:
package please;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;
public class please {
private Selenium selenium;
#Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://www.google.lk/");
selenium.start();
}
#Test
public void testPlease() throws Exception {
selenium.open("/?gfe_rd=cr&ei=10SKWaOqJ46AuATcuKPAAg");
selenium.type("id=lst-ib", "selenium");
selenium.type("id=lst-ib", "selenium");
assertEquals("selenium - Google Search", selenium.getTitle());
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
This is what the result looks like
Recording tests via Selenium IDE is rarely a good option, mainly because many code snippets has to be refactored, lack of abstraction, modularity and so on (list is quite long actually). Looking at your code, I think that the problem is in the driver you are trying to use. According to this selenium mirror at Github. You should migrate to using WebDriver, instead of DefaultSelenium:
#deprecated The RC interface will be removed in Selenium 3.0. Please migrate to using WebDriver.
So, Selenium Interface and DefaultSelenium Class both belong to Selenium 1 and are deprecated. Selenium has advanced to Selenium 3 (WebDriver).
You will want to use the following classes as these are part of Selenium 3 (WebDriver). WebDriver is an interface used by various Selenium 3 drivers.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Then you have various drivers that you can use. RemoteWebDriver / HtmlUnitDriver / FireFoxDriver / ChromeDriver / IEDriverServer etc. You will want to import the driver in your Java class.
Selenium selenium = new DefaultSelenium();
Becomes
WebDriver driver = new FireFoxDriver();
If your running the test using Selenium-Server try: (replace firefox with your browser version:
DesiredCapabilities capabillities= DesiredCapabilities.firefox();
capabillities.setCapability("platform", Platform.ANY);
capabillities.setCapability("name", "Testing Selenium-2 Remote WebDriver");
WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444/wd/hub"), capabillities);
driver.get("http://www.google.com");
assertEquals("Google", this.driver.getTitle());

Error with selenium webdriver code( geckodriver)

I am trying to run my first webdriver script in eclipse. using jre1.8.0_1111.
I used the following code but it shows error.please help me with the code.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Trial {
static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String baseUrl = "google.com";
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Naik\\Downloads\\geckodriver-v0.11.1-win64\\geck‌​odriver.exe");
driver.get(baseUrl);
}
Error stack
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 github.com/mozilla/geckodriver. The latest version can be downloaded from github.com/mozilla/geckodriver/releases
Download the geckodriver from the below URL and save it on your local machine.
https://github.com/mozilla/geckodriver/releases
Then set the right path where the geckodriver.exe is saved.Moreover the set property must be used before declaring the driver!
public class Trial {
public static void main(String[] args) {
String baseUrl = "google.com";
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Naik\\Downloads\\geckodriver-v0.11.1-win64\\geck‌​odriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
}
You need to first download GeckoDriver. After that, you can either add it to the PATH variable in environment variables sections, or you can set the path using "webdriver.gecko.driver" property. Check the below article for the steps -
http://www.automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
Also, please make sure that you are using the latest versions of Selenium, GeckoDriver and Firefox.
If you don't want to download geodriver, the other way is
Downgrade the Firefox browser version to 44 or more lesser and run your test.
https://ftp.mozilla.org/pub/firefox/releases/
Then you don't have to use gecko driver.
To downgrade firefox to lower version, first uninstall Firefox and the download and install from the link above mentioned

Running Seleniuem web driver 2.53.0 with Firefox 47.0

I have just started running test scripts using selenium web driver. I coded the following code as a start.
package myPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myTest {
public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
When I run it as Java application, It always shows the following error message.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Just the browser opens, but the facebook page doesn't get opened.
What is the solution for this?

Selenium Web Driver firefox not responding

I am using simple selenium example using Web driver classes, but the IE web driver class working fine, but the Firefox is not responding not opening browser and not throwing any error in console.
code is here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearchFF {
public static void main(String args[]){
WebDriver driver=new FirefoxDriver();
System.out.println("Loading Google search page");
driver.get("http://www.google.com");
System.out.println("Google search page loaded fine");
}
}
selenium jar files added to classpath..
\selenium-java-2.13.0\selenium-2.13.0\selenium-java-2.13.0.jar
\selenium-java-client-driver-1.0.1\selenium-java-client-driver.jar
\Selenium Latest\selenium-server-standalone-2.13.0.jar
any jar is missing?
The code works for IE by setting proeprty INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS = true
Downgrade the Firefox version to 8 as Selenium 2.13.0 supports Firefox versions upto 8 only.
For reference check this log.
Instead of downgrading Firefox to 8,
You need to download the geckodriver.exe and set the System.property() by
System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
before calling WebDriver driver = new FirefoxDriver();