[英]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服務器無法找到所需的元素。
您的主要問題似乎是所使用的二進制版本之間的不兼容 ,如下所示:
因此, JDK v1.8.0-131 , Selenium Client v3.4.0和IEDriverServer v3.12.0.0之間顯然不匹配。
在使用Selenium Java Client時 , InternetExplorerDriver和Internet Explorer瀏覽器確保:
@Test
。 tearDown(){}
方法內調用driver.quit()
,以優雅地關閉和破壞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")));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.