Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Chrome Driver can’t find elements after switching to new frame #1969

Closed
lukeis opened this issue Mar 2, 2016 · 30 comments
Closed

Chrome Driver can’t find elements after switching to new frame #1969

lukeis opened this issue Mar 2, 2016 · 30 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 1969

What steps will reproduce the problem?
1.RemoteWebDriver seleniumDriver= new ChromeDriver();
2.seleniumDriver.get("URL");
3.WebElement elementFrame=null;
4.elementFrame = seleniumDriver.findElement(By.xpath("//iframe[@class='ms-dlgFrame']"));
5.seleniumDriver.switchTo().defaultContent();
6.seleniumDriver.switchTo().frame(elementFrame);
7.List<WebElement> ElementList=seleniumDriver.findElements(By.xpath("//input[@value='Save']"));
8. System.out.println(ElementList.size());


What is the expected output? What do you see instead?
Selenium should be able to find input button. I have checked with Internet Explorer
8 and Firefox 3.6, where this code is working fine. But with Chrome driver Selenium
can’t find the element

What version of the product are you using? On what operating system?
Chrome Driver version:chromedriver_win32_13.0.775.0. 
OS: XP SP2
Chrome version: 12



Reported by writwiksinha on 2011-07-01 13:13:30

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am using selenium-server-standalone-2.0rc2.jar 

Reported by writwiksinha on 2011-07-01 14:42:16

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Can you provide the HTML for the page you are seeing this with?  The ChromeDriver passes
all of our tests that check for locating elements within a frame.

Reported by jmleyba on 2011-07-01 16:05:43

  • Status changed: NeedsClarification
  • Labels added: Component-WebDriver, Browser-Chrome

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am working on password protected SharePoint portal therefore can’t share the HTML.
I am describing the situation in more details.  When I click on a link, a modal popup
appears on the screen. This popup contains 2  iframe. Among them one iframe has unique
@class (Xpath: //iframe[@class='ms-dlgFrame']
), by which I can easily found iframe and prepare the webelement “elementFrame”(refer
to 5th step of What steps will reproduce the problem?
). This iframe contains the “Save” button. So I have tried to switch to that iframe
and click on that button. But unfortunately the Chrome driver can’t find the “Save”
button.IE driver and FF Driver do not experiences this problem.  

Reported by writwiksinha on 2011-07-01 16:41:57

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Can you create a small repro case that demonstrates the problem?

If not, can you check the frame switching actually worked (perhaps print out the page
url/title/source after step 6?)

Reported by kkania@chromium.org on 2011-07-01 16:55:04

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have try to print url, title and source after switching to iframe(ie, after step 6).
But its returning <html><head></head><body></body></html>,about:blank, about:blank
 respectively. Switching is not working properly. 

Reported by writwiksinha on 2011-07-04 06:22:58

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have found one interesting observation that selenium can successfully find the iframe,
so I can access iframe’s attributes(e.g  elementFrame.getAttribute("id") returning
correct id after step 4) . But switching to this iframe is not working.

Reported by writwiksinha on 2011-07-04 07:02:13

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Just throwing ideas around have you tried switching steps 4. and 5. ? 

{{{
4.seleniumDriver.switchTo().defaultContent();
5.elementFrame = seleniumDriver.findElement(By.xpath("//iframe[@class='ms-dlgFrame']"));
6.seleniumDriver.switchTo().frame(elementFrame);
}}}
Does it change the frame?

Reported by santeri.vesalainen@enersize.com on 2011-10-25 09:03:36

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by kkania@google.com on 2011-11-15 18:35:01

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have similar issue with chrome driver 16.0.902.0 and selenium 2.14.
The scenario is to log in and out on gmail, but after login and switching to the  canvas_frame
I get empty source and cant find the user name. The same code works just fine in FF
driver.
I use something like this

WebElement iFrame = getWebDriver().findElement(By.ById("canvas_frame");
getWebDriver().switchTo().frame(iFrame);

to switch to the frame. But I make sure with explicit waiting that the iFrame webelement
is found before switching into it.
Maybe only this overload of the switchTo() function is wrong, but Id like to use this,
because it is more general than the others and I don't always have name or ID to locate
the iframe.

Reported by ferenc.lombai on 2011-12-04 08:50:22

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have similar issue with chrome driver 16.0.902.0 and selenium 2.13 and 2.14.
WebElement iFrame = getWebDriver().findElement(By.ById("frame_id");
getWebDriver().switchTo().frame(iFrame);

Reported by gyorgy.hrabovszki on 2011-12-06 09:51:44

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

There is one weakness with switch to frame by element and index. If the frame ordering
changes, it may no longer point to the correct or even a valid frame.

If you can reproduce your problem consistently, can you try the following and see if
it fixes the problem:
1) Find the frame element
2) Set the ID or the name of the element to something (unless it already has one)
3) Switch to the frame by its ID or name

If this works, you are having a frame reordering problem. If it doesn't, you have a
different problem I'm not aware of.

Reported by kkania@google.com on 2012-01-12 18:52:31

  • Blocked on: #107751

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

You sir, are my new favourite person on the internet!   I can confirm that changing:

   IWebElement frame = Driver.FindElement(...)
   Driver.SwitchTo().Frame(frame); 

To 

   IWebElement frame = Driver.FindElement(...)
   Driver.switchTo().Frame( frame.GetAttribute("id") )

Does indeed fix my problem (once I'd changed the code-under-test to actually have identifiers
on the iframes!) 

Thank you.

Reported by ciaranj on 2012-01-13 08:44:45

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by kkania@google.com on 2012-01-27 22:01:11

  • Status changed: Accepted

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 2445 has been merged into this issue.

Reported by kkania@google.com on 2012-01-27 22:26:57

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by kkania@google.com on 2012-03-06 01:10:23

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Chromedriver v20 released, it is not blocked anymore and can be moved ahead.

Reported by barancev on 2012-06-01 20:25:14

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I could confirm that this still an issue with 2.21 with Chrome on a Mac.
switchTo().frame(String) works fine for me, but switchTo().frame(WebElement) sometimes
switch to some other iframe on the page.

Reported by Timofey.Basanov on 2012-06-15 22:18:14

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have a similar issue and am not sure if its the same issue.
For chrome driver I am not able to perform : List<WebElement> d = driver.findElements(By.tagName("iframe"));

Error : findElements returned invalid value: "[{\"ELEMENT\": \":wdc:1345117274332\"},
{\"ELEMENT\": \":wdc:1345117274333\"}, {\"ELEMENT\": \":wdc:1345117274334\"}, {\"ELEMENT\":
\":wdc:1345117274335\"}, {\"ELEMENT\": \":wdc:1345117274336\"}, {\"ELEMENT\": \":wdc:1345117274337\"},
{\"ELEMENT\": \":wdc:1345117274338\"}]" (WARNING: The server did not provide any stacktrace
information)

I am using selenium 2.25.

For IE and FF it works fine

Reported by kmahata on 2012-08-16 11:55:14

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@kmahata That is a separate issue.  It's been fixed, but you'll need to wait for the
next chromedriver release.

Reported by jmleyba on 2012-08-17 14:45:55

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

thanks for the update..waiting eagerly :)

Reported by kmahata on 2012-08-17 15:42:41

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Is this issue still actual?

Reported by barancev on 2013-02-23 18:04:44

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Is this issue still actual?

Reported by barancev on 2013-04-15 15:11:09

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I had this issue last week.

Reported by alan.justino.silva on 2013-04-15 19:45:06

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@alan.justino.silva: Do you have a reproduction scenario and a sample page?

Reported by barancev on 2013-04-16 06:53:34

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am receiving a NullPointerException (NPE) when using ChromeDriver with the following:

if (DriverInitializer.getDriver().findElement(By.cssSelector("div[aria-labelledby='ui-dialog-title-guidance-changed']")).getCssValue("display").trim()
                        .equalsIgnoreCase("block"))

FirefoxDriver and InternetExplorerDriver both execute the above without error.  Is
this the same issue?

I am using Version 27.0.1453.110 m of Google Chrome.

Reported by ann22301 on 2013-06-07 12:57:49

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@ann22301

That sounds a different issue. Something is returning null, I would assume either getDriver()
or .getCssValue(). This is different to this particular issue.

Reported by arran.huxtable on 2013-06-07 13:56:59

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

chromedriver:34 is known to be fixed in chromedriver2

Reported by barancev on 2013-08-14 20:10:17

  • Status changed: Fixed

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

This issue still happens with v2.10 of chromedriver. 

Reported by hkpanda on 2014-06-18 17:18:08

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

The supposed buggy way works now:

// works witb v2.10
IWebElement frame = Driver.FindElement(...)
Driver.SwitchTo().Frame(frame); 

Reported by hkpanda on 2014-06-18 17:39:19

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 18:13:09

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 2, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant