1

I am looking for element with ID "lastdays_day" as:

var elements = WebDriver.FindElements(By.Id("lastdays_day"));

but elements.Count is 0.

Even:

WebDriver.FindElements(By.CssSelector("*")) 

can not list this element

I have tried Thread.Sleep(5000) after page load but doesn't work. I have tried

Driver.SwitchTo().DefaultContent

or

Driver.SwitchTo().Frame(0)

but doesn't work.

Any ideas?

structure of the page

mojmir.novak
  • 2,920
  • 3
  • 24
  • 32
  • 1
    You have to find the iFrame first. Have a look at http://stackoverflow.com/questions/24247490/find-elements-inside-forms-and-iframe-using-java-and-selenium-webdriver – Arghya C May 15 '16 at 10:27
  • i am trying it but i have difficulty locate correct frame. It seems Selenium doesn't see even the frames. – mojmir.novak May 15 '16 at 11:35

1 Answers1

1

Driver.SwitchTo().DefaultContent; is to switch out of the frame.

Driver.SwitchTo().Frame(0); won't work either since indexes in the html starts from 1.

Driver.SwitchTo() can receives ID/name as parameter, so the switch command should look like

Driver.SwitchTo().Frame("ombframe"); // switch to first frame
Driver.SwitchTo().Frame("MainFrame"); // switch to second frame

As a side note, the ID of the element is lastdays_days with 's', not lastdays_day. It will also return only one element as ID is unique, so you can use WebDriver.FindElement

IWebElement element = WebDriver.FindElement(By.Id("lastdays_days"));
Guy
  • 46,488
  • 10
  • 44
  • 88
  • When i use Driver.SwitchTo().Frame("MainFrame"); i end up with: An exception of type 'OpenQA.Selenium.NoSuchFrameException' Additional information: No frame element found with name or id MainFrame – mojmir.novak May 15 '16 at 11:29
  • 1
    @mojmir.novak Try to switch to the parent frame first `Driver.SwitchTo().Frame("ombframe");`, and then to the frame with the element. – Guy May 15 '16 at 11:36
  • finally, it works :-) Please, it is there any way how to determine list of frames in page / or as children in parent frames? – mojmir.novak May 15 '16 at 11:46
  • @mojmir.novak You can see it in the html tree by the alignment. For example, frames `AppletFrame` and `MainFrame` are siblings, and children of the element above them with `` tag. – Guy May 15 '16 at 11:53
  • what i mean is if is here any function in Selenium what can give me a list of frames in runtime to I can search the element recursively in whole page. There are times i don't know the page structure or i don't want to care about frames. – mojmir.novak May 15 '16 at 11:56
  • 1
    @mojmir.novak No, there isn't. You have to tell the webdriver how to find the elements so it can interact with them, so it has to be done manually before running the code. – Guy May 15 '16 at 12:00
  • @Guy, SwitchTo().Frame is 0 based and not 1 based when an index is used as argument. – Florent B. May 15 '16 at 15:47