Chrome 如何克服“无效的状态代码=403文本=禁止”这个错误在 selenium 如果我们正在打开一个duplicictae浏览器在一个单独的端口

rsaldnfx  于 2023-03-27  发布在  Go
关注(0)|答案(1)|浏览(293)

请找到错误日志行:

ChromeDriver was started successfully.
Mar 14, 2023 12:13:48 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Invalid Status code=403 text=Forbidden
java.io.IOException: Invalid Status code=403 text=Forbidden
    at org.asynchttpclient.netty.handler.WebSocketHandler.abort(WebSocketHandler.java:92)
    at org.asynchttpclient.netty.handler.WebSocketHandler.handleRead(WebSocketHandler.java:118)
    at org.asynchttpclient.netty.handler.AsyncHttpClientHandler.channelRead(AsyncHttpClientHandler.java:78)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:336)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:444)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:280)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:280)

一种在不同端口地址打开单独副本浏览器的代码

public static void chromeSetup() {
    WebDriverManager.chromedriver().setup();
    ChromeOptions opt = new ChromeOptions();

    opt.setExperimentalOption("debuggerAddress", "localhost:9988");
    driver = new ChromeDriver(opt);
    
}

chromeSetup()在其他方法和类中实现,同时尝试打开url,例如:

if (reportType.equals("Y") || reportType.equals("y")) {
            chromeSetup();
            driver.get("sample url");
            exportButton();

            mainKey();

        } else if (reportType.equals("N") || reportType.equals("n")) {

            mainKey();

        }
bqucvtff

bqucvtff1#

你只需要添加这个选项,它就会工作
(“--远程允许源=*”);

相关问题