如何在IE中查找框架内的元素?

问题描述 投票:0回答:2

代码试用:

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)
java selenium internet-explorer iframe iedriverserver
2个回答
1
投票

此错误消息...

org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #MF\:txtentdon

...表示InternetExplorerDriver服务器无法找到所需的元素。

您的主要问题似乎是您使用的二进制文件版本之间不兼容,如下所示:

  • 您正在使用Selenium Java Client v3.4.0
  • 您正在使用IEDriverServer v3.12.0.0
  • 您正在使用JDK v1.8.0_131

因此,JDK v1.8.0-131,Selenium Client v3.4.0和IEDriverServer v3.12.0.0之间存在明显的不匹配。

在使用Selenium Java Client,InternetExplorerDriver和Internet Explorer Browser时,请确保:

  • 根据Required Configuration的文档,您已经完成了Native Events以及Browser FocusInternetExplorerDriver的其他注意事项。
  • 您已将JDK升级到最近的级别JDK 8u171
  • 您已将Selenium升级到当前水平Version 3.12.0
  • 您已将InternetExplorerDriver升级到当前的IEDriverServer v3.12.0级别。
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目。
  • 使用CCleaner工具在执行测试套件之前和之后擦除所有操作系统。
  • 进行系统重启。
  • 执行你的@Test
  • 始终在driver.quit()方法中调用tearDown(){}以正常关闭和销毁WebDriver和Web Client实例。

在将帧切换到定位元素时需要考虑的其他几个事实:

  • 切换到所需的帧时始终引入WebDriverwait。
  • 一旦切换到所需的帧,就会在查找所需元素时引发WebDriverwait。
  • 由于您所需的元素具有readOnly =“readonly”属性,因此您需要将ExpectedConditions用作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']")));

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")));
© www.soinside.com 2019 - 2024. All rights reserved.