IEDriver. After switching to an iFrame, I am unable to find any element on the page.

444 views
Skip to first unread message

Henry Pedersen

unread,
Apr 27, 2016, 9:56:11 AM4/27/16
to Selenium Users
I have a problem with the IEDriver. After switching to an iFrame, I am unable to find any element on the page.

Selenium.WebDriver.IEDriver.2.47.0.0 (32 bit) and 2.53.0.0 (32 bit)
IE Browser version 11
Windows Server 2008 R2

The HTML(pagesource) for the iFrame, after switching to it, looks like this:
<html><head><link href="/interactive/resources/ftb_p.css" rel="stylesheet" type="text/css"><link href="Wfd2CssHandler.axd?wfd=wfd%3a%2fIndustriensPension%2fBasicDocument.wfd**production*&amp;style=Text%2cParagraph%2cBorder&amp;filter=Web&amp;layout=&amp;stamp=635971858580570000" rel="stylesheet" type="text/css"><meta name="GENERATOR" content="MSHTML 11.00.9600.18283"></head><body class="ts_Normal Normal" style="border: 0px currentColor;" contentEditable="true"><p class="Normal"></p><span class="ts_Web_Brødtekst_ef2b5e0b">I forbindelse med din ansøgning har vi fået oplysninger fra &lt;indsæt hospitals navn&gt;. Vi har fået oplyst, at &lt;indsæt oplysningerne&gt;.</span></body></html>

The C# code that I try to run is:
var iframe = driver.FindElement(By.XPath("//iframe"));
driver.SwitchTo().Frame(iframe);
//Now the driver.pagesource is equal to the above html

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(6));
wait.Until(ExpectedConditions.ElementExists(By.XPath("//span")));

//Fails with "{"Timed out after 6 seconds"}"
//and with the innerException = {"The xpath expression '//span' cannot be evaluated or does notresult in a WebElement"}


//if I change the 2 codelines above with
IEnumerable<IWebElement> elements2 = driver.FindElements(By.TagName("span"));
//Then I get the error "An exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll but was not handled in user code
Additional information: Finding elements with tag name == spanreturned an unexpected error"

The C# code works fine with the Chrome Browser.

Why?

Henry Pedersen

unread,
May 3, 2016, 8:03:50 AM5/3/16
to Selenium Users
Still no ideas of what I should do to make my test Work in IE?

Maybe the following will trigger some ideas.

By using loging in the IEDriver, like so:

var service = InternetExplorerDriverService.CreateDefaultService();

service.LogFile = @"C:\IE.log";

service.LoggingLevel = InternetExplorerDriverLogLevel.Trace;

return new InternetExplorerDriver(service, options);


Then I get the following trace logs:

D 2016-05-03 13:46:49:029 ElementFinder.cpp(53) Using FindElement atom to locate element having xpath = //span
T 2016-05-03 13:46:49:029 Browser.cpp(120) Entering Browser::GetDocument
T 2016-05-03 13:46:49:029 Browser.cpp(602) Entering Browser::GetDocumentFromWindow
T 2016-05-03 13:46:49:036 Script.cpp(44) Entering Script::Initialize
T 2016-05-03 13:46:49:037 Script.cpp(65) Entering Script::AddArgument(std::wstring)
T 2016-05-03 13:46:49:037 Script.cpp(100) Entering Script::AddArgument(VARIANT)
T 2016-05-03 13:46:49:037 Script.cpp(65) Entering Script::AddArgument(std::wstring)
T 2016-05-03 13:46:49:037 Script.cpp(100) Entering Script::AddArgument(VARIANT)
T 2016-05-03 13:46:49:037 Script.cpp(164) Entering Script::Execute
T 2016-05-03 13:46:49:037 Script.cpp(472) Entering Script::CreateAnonymousFunction
W 2016-05-03 13:46:49:043 Script.cpp(489) -2147024891 [Access is denied.]: Unable to execute code, call to IHTMLWindow2::execScript failed
W 2016-05-03 13:46:49:043 Script.cpp(175) Cannot create anonymous function
W 2016-05-03 13:46:49:043 ElementFinder.cpp(84) Attempted to find element using invalid xpath: //span
T 2016-05-03 13:46:49:044 response.cc(76) Entering Response::SetErrorResponse
W 2016-05-03 13:46:49:044 response.cc(77) Error response has status code 32 and message 'The xpath expression '//span' cannot be evaluated or does notresult in a WebElement' message


Here I clearly get an error:

"Script.cpp(489) -2147024891 [Access is denied.]: Unable to execute code, call to IHTMLWindow2::execScript failed"


Does anyone know how I should go about this error. Is there some setup I should try beside the ones descriped at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

Henry Pedersen

unread,
May 4, 2016, 3:19:11 AM5/4/16
to Selenium Users
According to  https://msdn.microsoft.com/en-us/library/ms536420(v=vs.85).aspx, then "[execScript is no longer supported. Starting with Internet Explorer 11".
This must mean that there is an error in the IEDriver, an that IEDriver should be updated, right?


Den onsdag den 27. april 2016 kl. 15.56.11 UTC+2 skrev Henry Pedersen:

Jim Evans

unread,
May 4, 2016, 3:32:51 AM5/4/16
to Selenium Users
At the risk of being told yet again on this list that I don't know what I'm talking about, the problem isn't the IE driver's use of execScript. Finding elements after switching to a frame is not globally broken for all sites and all users in the IE driver. Without access to a site that reproduces the issue, I would be very hard pressed to suggest any other potential causes.
Reply all
Reply to author
Forward
0 new messages