0

Code trials:

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

Switching to Frame is may be successful but it didn't throw any NoSuchFrameException.

The same is working in Chrome and FireFox. But the same is not Working in IE (tried in IE9 and IE11). WebDriver Used: IEDriverServer Ver: 3.12.0.0

Is it because of the Document mode? or due to any Page rendering issue? In What Case will this happen?

HTML Source Code Link: Source Code

Tried to Find the id MF:txtentdon

I don't know if this is important or not, but It also throws HTTP Status: '404' -> incorrect JSON status mapping for 'stale element reference' (400 expected)

Error Stack Trace:

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)
Ray
  • 65
  • 1
  • 9
  • what xpath are you using ? update the question with xpath . try with different locators – cruisepandey Jun 05 '18 at 08:16
  • Please read why a [screenshot of HTML or code or error is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. – undetected Selenium Jun 05 '18 at 08:40
  • @DebanjanB I have updated with error stack trace. – Ray Jun 05 '18 at 10:08
  • @cruisepandey I have updated what xpath I used. And I have tried locators (id, cssSelector) – Ray Jun 05 '18 at 10:15
  • @cruisepandey One is input id and other is input name. Both have same value – Ray Jun 05 '18 at 10:17
  • My doubt is, why does **findElement(By.id("MF:txtentdon"))** returns Unable to find element with **css selector** == #MF\:txtentdon.. – Ray Jun 05 '18 at 10:33

2 Answers2

1

This error message...

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

...implies that the InternetExplorerDriver server was unable to locate the desired element.

Your main issue seems to be the incompatibility between the version of the binaries you are using as follows:

  • You are using Selenium Java Client v3.4.0
  • You are using IEDriverServer v3.12.0.0
  • You are using JDK v1.8.0_131

So there is a clear mismatch between JDK v1.8.0-131, Selenium Client v3.4.0 and IEDriverServer v3.12.0.0.

Solution

While you work with Selenium Java Client, InternetExplorerDriver and Internet Explorer Browser ensure that:

  • You have fulfilled the Required Configuration as well as the additional considerations for Native Events and Browser Focus as per the documentation of InternetExplorerDriver.
  • You have upgraded JDK to recent levels JDK 8u171.
  • You have upgraded Selenium to current levels Version 3.12.0.
  • You have upgraded InternetExplorerDriver to current IEDriverServer v3.12.0 level.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
  • Take a System Reboot.
  • Execute your @Test.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

A couple of additional facts you need to consider while switching frame to locate element:

  • Always induce WebDriverwait while switching to desired frame.
  • Once you switch to the desired frame induce WebDriverwait while you look out for the desired element.
  • As your desired element is having the attribute readOnly="readonly" so you need to use the ExpectedConditions as visibilityOfElementLocated() as follows:
  • So your effective code block will be:

    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']")));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I have tried this one and I got the below error: ` org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //input[@class='inputfld' and @id='MF:txtentdon'] (tried for 20 second(s) with 500 MILLISECONDS interval) at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:232) Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //input[@class='inputfld' and @id='MF:txtentdon']` – Ray Jun 05 '18 at 12:20
  • I don't know if this is important or not, but It also throws `INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'stale element reference' (400 expected)` – Ray Jun 05 '18 at 13:05
  • Hmmm, perhaps you need to cross check your _IEDriverServer_ configuration – undetected Selenium Jun 05 '18 at 13:07
  • I have already mentioned that I am using IE9 and IEDriverServer Version 3.12.0. Protected Mode is Enabled and Zoom Level is set to 100%. Any other configuration to be checked? – Ray Jun 05 '18 at 16:00
  • Even though it didn't throw `NoSuchFrameException` , I have a doubt whether it actually switched or not. – Ray Jun 06 '18 at 09:10
  • @Ray Checkout the updated answer and let me know the status, – undetected Selenium Jun 06 '18 at 10:32
  • I have done as you said, Still It couldn't find the element. Forget the element, I couldn't even print the iframes which are inside the **target iframe** using `List afterswitch = driver.findElements(By.tagName("iframe"));` after switching to the iframe, but it prints the iframes before the **target iframe** – Ray Jun 07 '18 at 09:49
0

You can try with this code :

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

Or

WebElement element =  new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.name("MF:txtentdon")));
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • `inside frame org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.name: MF:txtentdon (tried for 10 second(s) with 500 MILLISECONDS interval) at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)` – Ray Jun 05 '18 at 10:31
  • Is URL public ? – cruisepandey Jun 05 '18 at 10:40
  • No. It's not public – Ray Jun 05 '18 at 12:23
  • @Ray : are you facing stale element reference ? – cruisepandey Jun 05 '18 at 14:02
  • Actually I am getting an INFO below `INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'stale element reference' (400 expected)` – Ray Jun 05 '18 at 15:50