代码试用:
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)
答案 0 :(得分:1)
此错误消息......
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客户端, InternetExplorerDriver 和 Internet Explorer浏览器时,请确保:
@Test
。driver.quit()
方法中调用tearDown(){}
以关闭&正常销毁 WebDriver 和 Web客户端实例。在将帧切换到定位元素时需要考虑的其他几个事实:
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']")));
答案 1 :(得分:0)
您可以尝试使用以下代码:
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")));