selenium java.io.IOException:无效状态代码=403文本=禁止

vu8f3i0k  于 2023-03-12  发布在  Java
关注(0)|答案(5)|浏览(1663)

当我尝试执行一组Selenium Webdriver测试到Azure DevOps驱动程序到远程服务器时,我遇到了这个错误堆栈:

2023-03-08T21:06:46.9827484Z Running Test 66728 Mobile Web - Pick Task
2023-03-08T21:06:46.9827843Z Test Description https://dev.azure.com/Corporation/%20FootPrint/_workitems/edit/66728
2023-03-08T21:06:47.2244460Z Starting ChromeDriver 111.0.5563.41 (976ef12907ef9b413c2d929c043307b415d27b9e-refs/branch-heads/5563@{#737}) on port 35235
2023-03-08T21:06:47.2248489Z Only local connections are allowed.
2023-03-08T21:06:47.2273309Z Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2023-03-08T21:06:47.2530381Z ChromeDriver was started successfully.
2023-03-08T21:06:50.3292859Z Mar 08, 2023 4:06:50 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
2023-03-08T21:06:50.3319163Z WARNING: Invalid Status code=403 text=Forbidden
2023-03-08T21:06:50.3320374Z java.io.IOException: Invalid Status code=403 text=Forbidden
2023-03-08T21:06:50.3321045Z    at org.asynchttpclient.netty.handler.WebSocketHandler.abort(WebSocketHandler.java:92)
2023-03-08T21:06:50.3321498Z    at org.asynchttpclient.netty.handler.WebSocketHandler.handleRead(WebSocketHandler.java:118)
2023-03-08T21:06:50.3322255Z    at org.asynchttpclient.netty.handler.AsyncHttpClientHandler.channelRead(AsyncHttpClientHandler.java:78)
2023-03-08T21:06:50.3326071Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
2023-03-08T21:06:50.3334206Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
2023-03-08T21:06:50.3334813Z    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
2023-03-08T21:06:50.3335472Z    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
2023-03-08T21:06:50.3336148Z    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
2023-03-08T21:06:50.3336823Z    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333)
2023-03-08T21:06:50.3337255Z    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:454)
2023-03-08T21:06:50.3337683Z    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
2023-03-08T21:06:50.3339980Z    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
2023-03-08T21:06:50.3340463Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
2023-03-08T21:06:50.3343324Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
2023-03-08T21:06:50.3344253Z    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
2023-03-08T21:06:50.3344757Z    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
2023-03-08T21:06:50.3345262Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
2023-03-08T21:06:50.3345959Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
2023-03-08T21:06:50.3346524Z    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
2023-03-08T21:06:50.3346956Z    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
2023-03-08T21:06:50.3347371Z    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
2023-03-08T21:06:50.3347781Z    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
2023-03-08T21:06:50.3348183Z    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
2023-03-08T21:06:50.3348555Z    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
2023-03-08T21:06:50.3349009Z    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
2023-03-08T21:06:50.3349522Z    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
2023-03-08T21:06:50.3350108Z    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2023-03-08T21:06:50.3350574Z    at java.lang.Thread.run(Thread.java:748)

当我从我的电脑运行相同的代码,它的运行很好。你知道是不是有可能是WebDriver代码丢失,并为此原因,我得到这个错误?

s2j5cfk0

s2j5cfk01#

浏览了今天出现的一堆关于这个的不同帖子。大多数情况下的修复方法是在你的驱动示例中添加一个chromedriver选项。这就是让我再次工作的原因。
示例:选项。addArguments(“--远程允许原点=*”)

laximzn5

laximzn53#

在chrome选项中添加以下代码ChromeOptions options = new ChromeOptions();(“--远程允许源=*”);

ohfgkhjo

ohfgkhjo4#

相关的Selenium问题是https://github.com/SeleniumHQ/selenium/issues/11750
如果您升级到使用Java11 + HTTP客户端,它也适用于Selenium4.5+,如https://www.selenium.dev/blog/2022/using-java11-httpclient/中所述
基本上,将依赖项添加到

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-http-jdk-client</artifactId>
  <version>4.8.1</version>
</dependency>

并设置系统属性

System.setProperty("webdriver.http.factory", "jdk-http-client");
11dmarpk

11dmarpk5#

您应该添加以下代码以解决问题:java.io.IOException:无效状态代码=403 text=禁止和WebSocket处理程序

ChromeOptions option = new ChromeOptions();
            option.addArguments("--remote-allow-origins=*");

            WebDriverManager.chromedriver().setup();
            driver = new ChromeDriver(option);

相关问题