Could not start a new session. Response code 500. Message: session not created using Selenium Java with a downloaded chromedriver

huangapple go评论85阅读模式
英文:

Could not start a new session. Response code 500. Message: session not created using Selenium Java with a downloaded chromedriver

问题

当我尝试启动新的 Microsoft Edge 会话时,我遇到了这个错误:

未知问题:无法启动新会话。响应代码 500。消息:未创建会话
来自没有这样的执行上下文:在解析节点时加载器已更改
(会话信息:MicrosoftEdge=114.0.1823.79)
系统信息:os.name: 'Windows 10',os.arch: 'amd64',os.version: '10.0',java.version: '11.0.15'
驱动程序信息:org.openqa.selenium.edge.EdgeDriver

我已经研究过这个特定的错误,我找到的唯一解决方案是添加这两个参数:

--disable-dev-shm-usage
--remote-allow-origins=*

以及添加这个设置:

System.setProperty("webdriver.edge.driver", "driverpath");

这些操作我已经完成。

编辑:
这个问题只在我们的 CI 环境中出现,而且似乎是随机发生的。

英文:

When I try to start a new Microsoft Edge session, I encounter this error:
> Unknown Problem: Could not start a new session. Response code 500. Message: session not created
> from no such execution context: loader has changed while resolving nodes
> (Session info: MicrosoftEdge=114.0.1823.79)
> System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.15'
> Driver info: org.openqa.selenium.edge.EdgeDriver

I have already researched this specific error, and the only solution I found was to add these two arguments:
>--disable-dev-shm-usage
>--remote-allow-origins=*

and to add this setting:
>System.setProperty("webdriver.edge.driver", "driverpath");

which I have already done.

Edit:
This problem only occurs in our CI, and it happens kind of randomly.

答案1

得分: 1

如果您希望自动处理驱动程序版本/安装,我建议使用类似这样的Webdriver管理器。

您只需将依赖项添加到pom.xml

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.3.2</version>
    </dependency>

<!-- end snippet -->

参考链接

然后使用以下代码:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->
public class SiteTest extends BaseTest {

    @BeforeClass
    public static void setupAll() {
        WebDriverManager.edgedriver().setup();
    }

    @Test
    public void openSite() {
        WebDriver driver = new EdgeDriver();
        driver.get("https://example.com");
    }
}

<!-- end snippet -->

如果这对您有用 - 那么会话问题可能与驱动程序兼容性有关。

英文:

If you're wanting to handle drivers version / installation automatically, I suggest to use Webdriver manager like this

You can simply add dependency to pom.xml

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

        &lt;dependency&gt;
            &lt;groupId&gt;io.github.bonigarcia&lt;/groupId&gt;
            &lt;artifactId&gt;webdrivermanager&lt;/artifactId&gt;
            &lt;version&gt;5.3.2&lt;/version&gt;
        &lt;/dependency&gt;

<!-- end snippet -->

Reference

And then use code like

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

public class SiteTest extends BaseTest {

    @BeforeClass
    public static void setupAll() {
        WebDriverManager.edgedriver().setup();
    }

    @Test
    public void openSite() {
        WebDriver driver = new EdgeDriver();
        driver.get(&quot;https://example.com&quot;);
    }
}

<!-- end snippet -->

If this would work for you - so issue with session was in driver compatibility.

答案2

得分: 0

需要考虑以下几点:

  • 升级到 Selenium 版本 v4.6 或更高版本,这样 Selenium Manager 可以自动下载匹配的 EdgeDriver。因此,您可以移除以下代码:
System.setProperty("webdriver.edge.driver", "driverpath");
  • 在 Chrome 和 ChromeDriver 版本为 114.0 时,不再需要 --remote-allow-origins=*。因此,您可以删除它。

  • disable-dev-shm-usage 只有在使用 --no-sandbox 参数时才有效。因此,您可以删除它。

按照上述调整执行您的代码。

英文:

You need to consider a couple of things:

  • Upgrade to Selenium v4.6 or above so Selenium Manager can automatically download the matching EdgeDriver. So you can remove

    System.setProperty(&quot;webdriver.edge.driver&quot;, &quot;driverpath&quot;);
    
  • --remote-allow-origins=* is no more mandatory with Chrome and ChromeDriver version: 114.0. So you can drop it.

  • disable-dev-shm-usage isn't effective unless you are using the --no-sandbox argument. So you can drop it.

Making the above mentioned adjustments execute your code.

huangapple
  • 本文由 发表于 2023年7月13日 19:31:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定