Поиск вложенного iFrame с помощью Selenium 2 - PullRequest
9 голосов
/ 03 февраля 2012

Я пишу тесты для унаследованного приложения, в котором в основном документе есть iFrame, а затем еще один iFrame. Итак, иерархия:

Html Div (id = tileSpace)
  iFrame (id = ContentContainer)
    iFrame (id = Content)
      Elements

Это мой код (я использую C #)

RemoteWebDriver driver = new InternetExplorerDriver();
var tileSpace = driver.FindElement(By.Id("tileSpace"));
var firstIFrame = tileSpace.FindElement(By.Id("ContentContainer"));
var contentIFrame = firstIFrame.FindElement(By.Id("Content"));

Проблема в том, что я не могу перейти на 2-й уровень iFrame, т.е. contentIFrame

Есть идеи?

Ответы [ 2 ]

20 голосов
/ 04 февраля 2012

Я сейчас тестирую на похожем сайте.(вложенные фреймы внутри основного документа)

<div>
    <iframe>
        <iframe><iframe/>
    <iframe/>
</div>

Похоже, вы не используете метод переключения кадров , предоставляемый в Api.Это может быть проблемой.

Вот то, что я делаю, у меня работает нормально.

//make sure it is in the main document right now
driver.SwitchTo().DefaultContent();

//find the outer frame, and use switch to frame method
IWebElement containerFrame = driver.FindElement(By.Id("ContentContainer"));
driver.SwitchTo().Frame(containerFrame);

//you are now in iframe "ContentContainer", then find the nested iframe inside
IWebElement contentFrame = driver.FindElement(By.Id("Content"));
driver.SwitchTo().Frame(contentFrame);

//you are now in iframe "Content", then find the elements you want in the nested frame now
IWebElement foo = driver.FindElement(By.Id("foo"));
0 голосов
/ 04 февраля 2012

Попробуйте код ниже:

    //Switch to required frame
    driver.SwitchTo().Frame("ContentContainer").SwitchTo().Frame("Content");

    //find and do the action on required elements

    //Then come out of the iFrame
    driver.SwitchTo().DefaultContent();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...