Running Seleniuem web driver 2.53.0 with Firefox 47.0 - selenium

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?

Related

Error while invoking Internet Explorer browser using Selenium

Can anyone please help with the Selenium code below. I am getting an error while invoking Internet Explorer for automation testing.
Code :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","C:\\microsoftwebdriver\\MicrosoftWebDriver.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
}
}
Error screenshot attached:
InternetExplorerDriver
InternetExplorerDriver class is the WebDriver implementation that controls the IEServerDriver and and allows you to drive Internet Explorer browser running on the local machine. This class is provided as a convenience for easily testing the InternetExplorer browser. The control server which each instance communicates with will live and die with the instance.
To create a new instance of the IEServerDriver you need to use the IEServerDriver binary instead of MicrosoftWebDriver.exe which you need to download from selenium-release.storage, unzip and provide the absolute path within the System.setProperty() line. So your effective code block will be:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","C:\\path\\to\\IEServerDriver.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
}
}

In Mac, Selenium WebDriver is launching the browser successfully but is not opening by itself

The driver path is correct and hence a new chrome browser was launched successfully and ran the actions as per the code. However, i could not see those actions, because the newly launched chrome browser is not opening by itself. So i need to click on the browser manually to see the actions going on in browser. Tried with chrome and Firefox in Mac. How will the browser opens by itself? Here is the code which i tried
package trial;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Classname
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver","/usr/local/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
}
}
Here is the console logs
Starting ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8) on port 28190
Only local connections are allowed.
May 03, 2018 11:49:00 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

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());

Firefox not opening the specified URL when I run my webdriver program

I am new to automation with selenium and trying to run a basic program to launch Firefox and open Google.com. But I get Firefox launched with "about:blank&utm_content=firstrun" Please help. Am on Windows 10 and Firefox version is: 48.0 (latest). I have the latest Selenium drivers and JRE versions too.
Here is my code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleTest {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://google.com");
}
}

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();