Java Selenium - 无法启动 Selenium 会话:无法启动新的浏览器会话:启动浏览器时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1414934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 11:50:30  来源:igfitidea点击:

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

javaselenium

提问by Yatendra Goel

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 selenium 测试用例,它已成功编译。但是当我运行该测试时,我得到了以下 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.

这是我要运行的java文件。

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.

我首先通过命令提示符启动了selenium服务器,然后通过另一个命令提示符执行了上面的java文件。

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

第二个问题:我可以用 selenium 右键单击​​网页上的指定位置吗?

采纳答案by Santi

If you're using the last version of Selenium RC (after 1.0) you should change the following:

如果您使用的是最新版本的 Selenium RC(1.0 之后),您应该更改以下内容:

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

for

为了

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

If this doesn't work, try creating a separate firefox profile and using that one:

如果这不起作用,请尝试创建一个单独的 firefox 配置文件并使用该配置文件:

http://seleniumhq.org/docs/05_selenium_rc.html#specifying-the-firefox-profile

http://seleniumhq.org/docs/05_selenium_rc.html#specifying-the-firefox-profile

回答by Mugen

I know this might sound silly but are you sure you have given selenium.start()in your code? Beginners can make this mistake.

我知道这听起来很傻,但你确定你已经selenium.start()在你的代码中给出了吗?初学者可能会犯这个错误。

回答by Mugen

The setUp method basically invokes start method, so don't need to give selenium.start() in above code. I guess this is kind of selenium's bug. it stops testing before it get some response. but I've not found why yet.

setUp 方法基本上是调用 start 方法,所以不需要在上面的代码中给出 selenium.start() 。我想这是一种硒的错误。它在得到一些响应之前停止测试。但我还没有找到原因。

回答by SHANMUGAVEL

Always make sure, selenium.stop()method has been called at the end of test steps.

始终确保selenium.stop()在测试步骤结束时调用了方法。

回答by benklaasen

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.

这个问题很可能是由一个已经在运行的 Selenium 服务器实例引起的。新实例需要侦听相同的端口号,但不能,因为该端口已在使用中。

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

假设您的 Selenium 服务器配置为在端口 4444 上启动。使用“netstat”命令确定该端口是否正在使用中:

On Windows: netstat -an | find "4444"

在 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

在 Linux 上,使用: netstat -anp | grep 4444

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

(手头没有 Linux 机器,因此无法显示示例输出!)

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 -anbto 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>.

如果您看到任何输出,则需要终止正在侦听 Selenium 想要使用的端口的进程。在 Windows 上,用于netstat -anb查找进程名称(它将列在指定端口号的行之后)。使用任务管理器杀死它。在 Linux 上,进程 PID 和名称将由上面的命令列出 - 使用kill <PID>.