Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在IE中找到框架内的元素?_Java_Selenium_Internet Explorer_Iframe_Iedriverserver - Fatal编程技术网

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

Java 如何在IE中找到框架内的元素?,java,selenium,internet-explorer,iframe,iedriverserver,Java,Selenium,Internet Explorer,Iframe,Iedriverserver,代码试用: driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'path')]"))); driver.findElement(By.id()); 切换到Frame is可能会成功,但未引发任何NoSuchFrameException Chrome和FireFox也是如此。但同样的方法在IE中不起作用(在IE9和IE11中尝试过)。 使用的WebDriver:IEDriverServer版本:

代码试用:

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'path')]")));
driver.findElement(By.id());
切换到Frame is可能会成功,但未引发任何NoSuchFrameException

Chrome和FireFox也是如此。但同样的方法在IE中不起作用(在IE9和IE11中尝试过)。 使用的WebDriver:IEDriverServer版本:
3.12.0.0

是因为文档模式吗?或者由于任何页面呈现问题? 在什么情况下会发生这种情况

HTML
源代码链接:

试图找到id
MF:txtentdon


我不知道这是否重要,但它也会抛出
HTTP状态:“404”->“stale element reference”(预期400)的不正确JSON状态映射。

错误堆栈跟踪:

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)

您可以尝试使用以下代码:

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")));
此错误消息

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.0131
因此,JDK v1.8.0-131、Selenium Client v3.4.0和IEDriverServer v3.12.0.0之间存在明显的不匹配

解决方案 使用Selenium Java客户端时,InternetExplorerDriver和Internet Explorer浏览器确保:

  • 您已完成的以及的文档中的其他注意事项
  • 您已将JDK升级到最新级别
  • 您已将Selenium升级到当前级别
  • 您已将InternetExplorerDriver升级到当前级别
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • 在执行测试套件之前和之后,使用该工具清除所有操作系统杂务
  • 重新启动系统
  • 执行
    @测试
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

在切换帧定位元素时需要考虑的另外两个事实:

  • 切换到所需帧时,始终导入WebDriverwait
  • 一旦切换到所需的帧,请在查找所需元素的同时将其删除
  • 由于所需元素具有属性readOnly=“readOnly”,因此需要按如下方式使用预期条件:
  • 因此,您的有效代码块将是:

    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']")));
    

您使用的是什么xpath?用xpath更新问题。尝试使用不同的定位器请阅读原因。考虑使用格式化的基于文本的HTML、代码试验和错误堆栈跟踪更新问题。@ DEBANJANB我已经更新了错误堆栈跟踪。@ CraceSePeDey我已经更新了XPath i所使用的内容。我试过定位器(id,cssSelector)@cruisepandey一个是输入id,另一个是输入名称。两者在框架org.openqa.selenium.TimeoutException内具有相同的值
:预期条件失败:等待元素可单击:By.name:MF:txtentdon(在org.openqa.selenium.support.ui.WebDriverWait.TimeoutException(WebDriverWait.java:80)处尝试10秒,间隔500毫秒)
URL是公共的吗?不,不是public@Ray:您是否面临过时的元素引用?实际上,我在下面得到了一个信息
INFO:HTTP Status:'404'->“过时的元素引用”的JSON状态映射不正确(预期为400)
我尝试了这一次,但得到了以下错误:`org.openqa.selenium.TimeoutException:预期条件失败:等待位于org.openqa.selenium.support.ui.WebDriverWait.TimeoutException的元素的可见性,路径为:xpath://input[@class='inputfld'和@id='MF:txtentdon'](尝试了20秒,间隔500毫秒)(WebDriverWait.java:80)位于org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:232),原因是:org.openqa.selenium.NoSuchElementException:无法使用by.xpath://input[@class='inputfld'和@id='MF:txtentdon'定位元素`我不知道这是否重要,但它也会抛出
INFO:HTTP Status:'404'->“stale element reference”的不正确JSON状态映射(预计为400)
Hmmm,也许你需要交叉检查你的IEDriverServer配置我已经提到我正在使用IE9和IEDriverServer版本3.12.0。保护模式已启用,缩放级别设置为100%。要检查的任何其他配置?即使它没有抛出
NoSuchFrameException
,我仍怀疑它是否实际存在不管你是不是换了。