最近,我将 Selenium 版本从 2.53 升级到 4.1.2,以便能够在 MS EDGE IE11 上测试我们的应用程序。但是,当我们使用简单的 Selenium .clear() 清除任何 TextBox 字段时,我们不断面临问题。虽然,其各自的清除,但也抛出以下异常。
还有其他人在 Selenium-4.1.2 上遇到过类似的问题吗?
例外:
org.openqa.selenium.InvalidElementStateException:JavaScript 错误
遇到清除元素的情况。司机认为这是
因为该元素是隐藏的、禁用的或只读的,并且它不能
是为了清除元素。构建信息:版本:'4.1.2',修订版:
'9a5a329c5a' 系统信息:os.name:'Windows 10',os.arch:'amd64',
os.version: '10.0', java.version: '1.8.0_222' 驱动程序信息:
org.openqa.selenium.ie.InternetExplorerDriver 命令:
[69d06b0b-b468-455b-9d3c-24626ad40e16,清除元素
{id=2bb89cb8-5d24-4dd8-8e3a-be8fa7e1272e}] 功能
{acceptInsecureCerts: false, browserName: 互联网浏览器,
browserVersion:11,javascriptEnabled:true,pageLoadStrategy:正常,
平台:WINDOWS,平台名称:WINDOWS,代理:Proxy(),
se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0,
enablePersistentHover: true, ie.browserCommandLineSwitches: ,
ie.edgechromium: false, ie.edgepath: , ie.ensureCleanSession: false,
ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false,
ignoreProtectedModeSettings:假,ignoreZoomSetting:假,
初始浏览器网址:http://localhost:54726/,nativeEvents:true,
requireWindowFocus: false}, setWindowRect: true,
strictFileInteractability:假,超时:{隐式:0,pageLoad:
300000,脚本:30000},unhandledPromptBehavior:解雇并通知}
元素:[[InternetExplorerDriver:WINDOWS 上的 Internet Explorer
(69d06b0b-b468-455b-9d3c-24626ad40e16)]-> id: userid] 会话 ID:
69d06b0b-b468-455b-9d3c-24626ad40e16 在
sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
在
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
在
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在 java.lang.reflect.Constructor.newInstance(Constructor.java:423) 处
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
在
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
在
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
在
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
在
org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
在
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
在
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:558)
在
org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:251)
在
org.openqa.selenium.remote.RemoteWebElement.clear(RemoteWebElement.java:126)
期望:我们期望 clear()
应该清除该字段而不引发任何异常。
Recently, I have upgraded my Selenium version from 2.53 to 4.1.2 to enable testing of our application on MS EDGE IE11. But we are continuously facing issue when we are clearing any TextBox field using simple Selenium .clear(). Although, its clearing that respective and but also throwing below exception.
Did anyone else facing similar kind of issues with Selenium-4.1.2 ?
Exception:
org.openqa.selenium.InvalidElementStateException: A JavaScript error
was encountered clearing the element. The driver assumes this is
because the element is hidden, disabled or read-only, and it must not
be to clear the element. Build info: version: '4.1.2', revision:
'9a5a329c5a' System info: os.name: 'Windows 10', os.arch: 'amd64',
os.version: '10.0', java.version: '1.8.0_222' Driver info:
org.openqa.selenium.ie.InternetExplorerDriver Command:
[69d06b0b-b468-455b-9d3c-24626ad40e16, clearElement
{id=2bb89cb8-5d24-4dd8-8e3a-be8fa7e1272e}] Capabilities
{acceptInsecureCerts: false, browserName: internet explorer,
browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal,
platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(),
se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0,
enablePersistentHover: true, ie.browserCommandLineSwitches: ,
ie.edgechromium: false, ie.edgepath: , ie.ensureCleanSession: false,
ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false,
ignoreProtectedModeSettings: false, ignoreZoomSetting: false,
initialBrowserUrl: http://localhost:54726/, nativeEvents: true,
requireWindowFocus: false}, setWindowRect: true,
strictFileInteractability: false, timeouts: {implicit: 0, pageLoad:
300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Element: [[InternetExplorerDriver: internet explorer on WINDOWS
(69d06b0b-b468-455b-9d3c-24626ad40e16)] -> id: userid] Session ID:
69d06b0b-b468-455b-9d3c-24626ad40e16 at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:558)
at
org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:251)
at
org.openqa.selenium.remote.RemoteWebElement.clear(RemoteWebElement.java:126)
Expectation : We expect clear()
should clear the field without throwing any exception.
发布评论
评论(2)
这是由于边缘模式驱动程序中的错误
https://github.com/seleniumhq/seleniumhq/selenium/selenium/issues/10488 将使用javascriptexecutor定位和清除输入字段
This is due to a bug in the Edge IE mode driver
https://github.com/SeleniumHQ/selenium/issues/10488
A possible workaround would be to use JavascriptExecutor to locate and clear the input field
invalidelementStateException 表明webelement处于某种状态,在某种状态下无法执行任何操作。几个示例将包括一个单击时被另一个元素遮盖的元素,或者可能在DOM上不可见。
解决方案
始终建议 clear 任何
< input>
字段您需要诱导 em> 对于元素( javascript )to render html dom 单击() 如下:InvalidElementStateException indicates that a WebElement is in a certain state in which actions cannot be performed with it. A couple of examples would include an element being obscured by another when clicking, or perhaps not being visible on the DOM.
Solution
It is always recommened that to clear any
<input>
field you need to induce WebDriverWait to elementToBeClickable() for the element (JavaScript) to render the HTML DOM completely before you invokeclick()
as follows: