单击图像时“元素无法单击”-Selenium WebDriver Java [重复]
Posted
技术标签:
【中文标题】单击图像时“元素无法单击”-Selenium WebDriver Java [重复]【英文标题】:“Element is not clickable at point” when clicking on an Image - Selenium WebDriver Java [duplicate] 【发布时间】:2018-06-11 06:08:55 【问题描述】:我是测试自动化和 Selenium WebDriver 的新手。
我正在尝试自动化私人网站的验证系统。
我们的目标是自动化订单管理系统,让店主可以确认他前几天收到的几份订单。
需要TestAutomation,因为他必须每2/3天确认一次700/800订单。
他所做的(以及我试图自动化的)基本上是这样的,由以下几点解释:
1) 他使用自己的凭据登录系统
2) 进入安全区域后,他有一个搜索文本框,可以在其中键入客户的姓名,然后按 Enter 按钮确认,然后被重定向到客户详细信息页面。
3) 在这里,为了确认订单,他点击了一张图片(代表发票的扫描)并确认出现的警报上的“是”按钮。
我所做的是创建一个包含 800 行的 txt 文件,代表 800 位客户,并在研究他们的订单并通过单击图像进行确认时循环访问它们。
我的问题是,有时我的 ChromeDriver 不会点击图像,即使它是可见的,我也会收到以下运行时错误:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1121172875.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
... 60 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: Element <div class="_mck9w _gvoze _tn0ps">...</div> is not clickable at point (353, 495). Other element would receive the click: <div class="_gftfm"></div>
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
System info: host: 'PC-CASA', ip: '192.168.0.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_20'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: chromedriverVersion: 2.30.477700 (0057494ad87321..., userDataDir: C:\Users\Zakaria\AppData\Lo..., cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 63.0.3239.84, webStorageEnabled: true
Session ID: b87555cc792c28d8bd14e3d2d1b7c888
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at com.derossiSpa.bot.pageModule.Confirm_Action.execute(Confirm.java:21)
at com.derossiSpa.bot.view.BotController.startBot(BotController.java:144)
... 69 more
这就是我处理图片点击的方式。
try
WebElement invoiceImage = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='react-root']/section/main/article/div[2]/div/div[1]/div[1]")));
Thread.sleep(400);
invoiceImage.click();
catch(org.openqa.selenium.StaleElementReferenceException ex)
WebElement invoiceImage = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='react-root']/section/main/article/div[2]/div/div[1]/div[1]")));
Thread.sleep(400);
invoiceImage.click();
运行时错误实际上是随机发生的,有时我在正确点击 10 张图片后得到它,有时在 40 张图片之后,有时甚至仅在 1 张图片之后。
关于分辨率的任何想法?
【问题讨论】:
尝试在点击事件之前添加一些等待 我最初在 2500 毫秒时拥有它,但在点击 40 次 @AnkurSingh 后它失败了。我的意思是,如果这是唯一的解决方案,我可以将其增加到 5000 或 10000,但我想以更聪明的方式来做 未知错误:元素 ... 在点 (353, 495) 不可点击。其他元素会收到点击: 你所显示的错误是它点击了图片链接上的其他部分。所以添加〜5000ms的等待 @AnkurSingh 谢谢我的朋友,使用 ~5000ms 它不会失败!但是没有办法只等待必要的时间。我的意思是,有时图片会立即加载,但我必须等待 5000。类似 smartWait 的东西,而不是 Thread.sleep() @user9159143 你能提供网址吗?因此,通过查看上下文,我们可以决定智能等待。 【参考方案1】:你使用了错误堆栈中的 chromedriver 2.30
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.30.477700
not clickable at point
是下面链接中描述的 chromedriver 2.30 上的一个已知问题,请将您的 chromedriver 更新到 2.33 或最新版本应该可以解决您的问题。
https://bugs.chromium.org/p/chromedriver/issues/detail?id=1852
【讨论】:
以上是关于单击图像时“元素无法单击”-Selenium WebDriver Java [重复]的主要内容,如果未能解决你的问题,请参考以下文章