簡體   English   中英

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

[英]How to find an element within a frame in IE?

代碼試用:

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'path')]")));
driver.findElement(By.id());

切換到框架可能是成功的,但沒有引發任何NoSuchFrameException。

在Chrome和FireFox中也是如此。 但是,在IE中無法正常工作(在IE9和IE11中進行了嘗試)。 使用的WebDriver:IEDriverServer版本: 3.12.0.0

是否由於文檔模式? 還是由於任何頁面渲染問題? 在什么情況下會發生這種情況?

HTML源代碼鏈接: 源代碼

試圖找到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服務器無法找到所需的元素。

您的主要問題似乎是所使用的二進制版本之間的不兼容 ,如下所示:

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

因此, JDK v1.8.0-131Selenium Client v3.4.0IEDriverServer v3.12.0.0之間顯然不匹配。

在使用Selenium Java Client時InternetExplorerDriverInternet Explorer瀏覽器確保:

  • 您已經按照InternetExplorerDriver的文檔完成了必需的配置以及本機事件瀏覽器焦點的其他注意事項。
  • 您已將JDK升級到最新級別的JDK 8u171
  • 您已經將Selenium升級到當前版本3.12.0
  • 您已將InternetExplorerDriver升級到當前的IEDriverServer v3.12.0級別。
  • 通過IDE 清理 項目工作區 ,並僅使用必需的依賴項重建項目。
  • 在執行測試套件之前和之后,使用CCleaner工具清除所有操作系統瑣事。
  • 進行系統重啟
  • 執行您的@Test
  • 始終在tearDown(){}方法內調用driver.quit() ,以優雅地關閉和破壞WebDriverWeb 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']"))); 

您可以嘗試使用以下代碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM