配置selenium环境后,在idea启动,driver.get(XXX)报错,

报错一:

esponse DefaultHttpResponse(decodeResult: success, version: HTTP/1.1) HTTP/1.1 403 Forbidden Content-Length: 241 Content-Type: text/html

4月 06, 2023 10:22:10 上午 org.openqa.selenium.remote.http.WebSocket$Listener onError 警告: 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:346)     at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333)     at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:454)     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)     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)     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.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)     at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)     at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)     at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)     at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)     at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)     at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)     at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)     at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)     at java.base/java.lang.Thread.run(Thread.java:833)

10:22:10.948 [AsyncHttpClient-1-4] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Closing Channel [id: 0x9769ccd7, L:/127.0.0.1:61305 - R:localhost/127.0.0.1:61296]  10:22:10.950 [AsyncHttpClient-1-4] DEBUG org.asynchttpclient.netty.handler.WebSocketHandler - Channel Closed: [id: 0x9769ccd7, L:/127.0.0.1:61305 ! R:localhost/127.0.0.1:61296] with attribute DISCARD

org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:61296/devtools/browser/5958aa28-167c-437d-9b22-7e0349a3cf7e Build info: version: '4.5.3', revision: '4b786a1e430'

解决:创建driver添加option选项

ChromeOptions option = new ChromeOptions();

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

WebDriver driver=new ChromeDriver(option);

2023.4.9学习

浏览器,获取元素,F12打开开发者工具,点击elements相应元素右键-copy-   有几种方式:比如xpath。

检查路径是否唯一的方法:F12之后,ctrl+F,在输入框粘贴路径,如果出现1 of 1字样,则说明查找元素唯一。

问题:hover到某一个元素,出现下拉框,如何选中其中一个选项(百度首页右上方就有类似操作,登陆后,退出)

相关链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: