代码试用:
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'path')]")));
driver.findElement(By.id());
切换到Frame可能是成功的,但它没有抛出任何NoSuchFrameException。
这同样适用于Chrome和FireFox。但同样不是在IE中工作(在IE9和IE11中尝试过)。使用的Web驱动程序:IEDriverServer Ver:3.12.0.0
是因为文档模式吗?或者由于任何页面呈现问题?在什么情况下会发生这种情况?
HTML
源代码链接:Source Code
试图找到id MF:txtentdon
我不知道这是否重要,但它也会引发HTTP Status: '404' -> incorrect JSON status mapping for 'stale element reference' (400 expected)
错误堆栈跟踪:
org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #MF\:txtentdon
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'N9776', ip: '172.29.18.139', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{proxy=Proxy(), acceptInsecureCerts=false, browserVersion=9, se:ieOptions={nativeEvents=true, browserAttachTimeout=0.0, ie.ensureCleanSession=false, elementScrollBehavior=0.0, enablePersistentHover=true, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:6017/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000.0, ignoreProtectedModeSettings=false}, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true, platformName=windows, setWindowRect=true, platform=ANY}]
Session ID: 48da0488-5d2e-46db-996e-77f27f26ff28
*** Element info: {Using=id, value=MF:txtentdon}
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:410)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:453)
at org.openqa.selenium.By$ById.findElement(By.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402)
此错误消息...
org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #MF\:txtentdon
...表示InternetExplorerDriver服务器无法找到所需的元素。
您的主要问题似乎是您使用的二进制文件版本之间不兼容,如下所示:
因此,JDK v1.8.0-131,Selenium Client v3.4.0和IEDriverServer v3.12.0.0之间存在明显的不匹配。
在使用Selenium Java Client,InternetExplorerDriver和Internet Explorer Browser时,请确保:
@Test
。driver.quit()
方法中调用tearDown(){}
以正常关闭和销毁WebDriver和Web Client实例。在将帧切换到定位元素时需要考虑的其他几个事实:
visibilityOfElementLocated()
,如下所示:new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@src,'path')]")));
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@class='inputfld' and @id='MF:txtentdon']")));
您可以尝试使用以下代码:
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'path')]")));
System.err.println("inside frame");
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("MF:txtentdon")));
要么
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.name("MF:txtentdon")));