Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium - Could not start Selenium session: Failed to start new browser session: Error while launching browser

Tags:

java

selenium

I am new to Selenium. I generated my first java selenium test case and it has compiled successfully. But when I run that test I got the following RuntimeException

java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser at com.thoughtworks.selenium.DefaultSelenium.start <DefaultSelenium.java:88>

Kindly tell me how can I fix this error.

This is the java file I want to run.

import com.thoughtworks.selenium.*;

import java.util.regex.Pattern;

import junit.framework.*;

public class orkut extends SeleneseTestCase {

 public void setUp() throws Exception {

  setUp("https://www.google.com/", "*chrome");

 }
 public void testOrkut() throws Exception {

  selenium.setTimeout("10000");

  selenium.open("/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0&cd=IN&skipvpage=true&sendvemail=false");

  selenium.type("Email", "username");

  selenium.type("Passwd", "password");

  selenium.click("signIn");

  selenium.selectFrame("orkutFrame");

  selenium.click("link=Communities");

  selenium.waitForPageToLoad("10000");

 }

 public static Test suite() {

  return new TestSuite(orkut.class);

 }

 public void tearDown(){

  selenium.stop();

 }

 public static void main(String args[]) {

  junit.textui.TestRunner.run(suite());

 }

}

I first started the selenium server through the command prompt and then execute the above java file through another command prompt.

Second Question: Can I do right click on a specified place on a webpage with selenium.

like image 780
Yatendra Avatar asked Feb 04 '23 09:02

Yatendra


1 Answers

Chances are this problem is caused by an already-running instance of the Selenium server. The new instance needs to listen on the same port number, but can't, because the port is already in use.

Let's say your Selenium server is configured to start on port 4444. Determine if the port is in use using the 'netstat' command:

On Windows: netstat -an | find "4444"

Expect to see output like this:

  TCP    0.0.0.0:4444           0.0.0.0:0              LISTENING
  TCP    [::]:4444              [::]:0                 LISTENING

On Linux, use: netstat -anp | grep 4444

(No Linux box to hand, so can't show example output!)

If you see any output, you need to kill the process that's listening on the port that Selenium wants to use. On Windows, use netstat -anb to find the process name (it'll be listed after the line specifying the port number). Kill it using the Task Manager. On Linux, the process PID and name will be listed by the command above - kill it using kill <PID>.

like image 197
benklaasen Avatar answered Feb 06 '23 15:02

benklaasen