【问题标题】:Unable to find locate frame/Modal Dialog from sitecore and do actions inside无法从 sitecore 找到定位框架/模态对话框并在内部执行操作
【发布时间】:2016-09-09 13:09:36
【问题描述】:

下面是我卡住的页面截图:

下面是 HTML 的截图:

HTML

<iframe id="scContentIframeId0" frameborder="0" scrolling="auto" class="ui-dialog-content ui-widget-content ui-dialog-normal" src="/sitecore/shell/Applications/Dialogs/External link.aspx?hdl=F66BB6924018478682797A717320B5DB&amp;ro&amp;la=en&amp;sc_content" style="width: auto; min-height: 0px; max-height: none; height: 285px;"></iframe>
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-draggable ui-resizable" tabindex="-1" role="dialog" aria-describedby="scContentIframeId0" aria-labelledby="ui-id-1" style="position: absolute; height: auto; width: 500px; top: 117.5px; left: 308px; display: block; opacity: 1;">
   <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
      <span id="ui-id-1" class="ui-dialog-title">&nbsp;</span>
      <div class="ui-dialog-titlebar-buttonpane" style="position: absolute; top: 50%; right: 0.3em; margin-top: -10px; height: 18px;"><button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" role="button" aria-disabled="false" title="close" style="position: relative; float: right; top: auto; right: auto; margin: 0px;"><span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span></button><a class="ui-dialog-titlebar-restore ui-corner-all ui-state-default" href="#" role="button" style="display: none;"><span class="ui-icon ui-icon-newwin">restore</span></a><a class="ui-dialog-titlebar-collapse ui-corner-all ui-state-default" href="#" role="button" style="display: none;"><span class="ui-icon ui-icon-triangle-1-s">collapse</span></a><a class="ui-dialog-titlebar-maximize ui-corner-all ui-state-default" href="#" role="button"><span class="ui-icon ui-icon-extlink">maximize</span></a><a class="ui-dialog-titlebar-minimize ui-corner-all ui-state-default" href="#" role="button" style="display: none;"><span class="ui-icon ui-icon-minus">minimize</span></a></div>
   </div>
   <iframe id="scContentIframeId0" frameborder="0" scrolling="auto" class="ui-dialog-content ui-widget-content ui-dialog-normal" src="/sitecore/shell/Applications/Dialogs/External link.aspx?hdl=F66BB6924018478682797A717320B5DB&amp;ro&amp;la=en&amp;sc_content" style="width: auto; min-height: 0px; max-height: none; height: 285px;"></iframe>
   <div class="ui-resizable-handle ui-resizable-n" style="z-index: 90;"></div>
   <div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"></div>
   <div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"></div>
   <div class="ui-resizable-handle ui-resizable-w" style="z-index: 90;"></div>
   <div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"></div>
   <div class="ui-resizable-handle ui-resizable-sw" style="z-index: 90;"></div>
   <div class="ui-resizable-handle ui-resizable-ne" style="z-index: 90;"></div>
   <div class="ui-resizable-handle ui-resizable-nw" style="z-index: 90;"></div>
</div>

我试图找到这个框架并通过定位元素在其中执行操作。但我无法这样做。尝试使用 Frame id - scContentIframeId0、Xpaths、类名,但没有结果。

下面是我的 Selenium c# 代码

IWebElement IFrame = driver.FindElement(By.Id("scContentIframeId0"));
            driver.SwitchTo().Frame(IFrame);
IWebElement LinkDescription = driver.FindElement(By.XPath("//*[@id='Text']"));
            LinkDescription.SendKeys("External Link");
IWebElement URL = driver.FindElement(By.XPath("//*[@id='Url']"));
            URL.SendKeys("www.irctc.co.in");
            IWebElement OKButton = driver.FindElement(By.XPath("//*[@id='OK']"));

            OKButton.Click();

请帮忙。

异常堆栈跟踪结果:

Test method ComcastnowTest.Content_Event_RSVP_US688833.EventRSVPlink threw exception: 
OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"scContentIframeId0"}
  (Session info: chrome=52.0.2743.116)
  (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.1.7601 SP1 x86_64)
Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at ComcastnowTest.Content_Event_RSVP_US688833.EventRSVPlink()

【问题讨论】:

  • 您实际上要定位哪个元素??
  • 请查看所提供链接中的屏幕截图。你会在屏幕截图中看到一个框架,在里面我想用它的元素做一些动作。但问题是,我的代码无法识别框架本身,因此无法继续进行
  • 正如我在提供的 HTML iframe 中看到的那样,开始然后关闭这些 iframes 中不存在的元素?所以你确定欲望元素在iframe里面吗?以及您要实际定位的元素?因为在提供的 HTML 中没有 ID 为 TextUrlOk 的元素。那么您能否详细说明您的问题..
  • 附上框架内元素的 HTML 截图
  • 好的,我已经提供了它作为答案,尝试一下,让我知道..

标签: c# selenium-webdriver modal-dialog sitecore sitecore7


【解决方案1】:

我认为这是时间问题,您应该尝试使用 WebDriverWait 等到 iframe 出现在 DOM 上,然后切换到它:-

IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));

//Now wait for iframe to available and then switch 
 wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt("scContentIframeId0"));

//Now find desire element inside this iframe 
IWebElement LinkDescription = wait.Until(ExpectedConditions.ElementExists(By.Id("Text")));
LinkDescription.SendKeys("External Link");

//Now after performing all stuff inside iframe switch back to default content 
driver.SwitchTo().DefaultContent(); 

【讨论】:

  • 感谢您的回复,但仍然出现错误
  • 结果消息:测试方法 ComcastnowTest.Content_Event_RSVP_US688833.EventRSVPlink 抛出异常:OpenQA.Selenium.WebDriverTimeoutException:3 秒后超时结果 StackTrace:在 OpenQA.Selenium.Support.UI.DefaultWait1.ThrowTimeoutException(String exceptionMessage, Exception lastException) at OpenQA.Selenium.Support.UI.DefaultWait1。直到[TResult](Func`2 条件)
  • 再三思考,我也在考虑这是否与模态框有关。但是,嘿,任何可以解决这个问题的解决方案都会很方便!!
  • @RuthlessNike 你能告诉我这个TimeoutExceptio‌​n 出现在哪一行吗?在帧切换期间或在通过 id 查找元素期间??
  • 发生在换帧后。它根本无法识别框架。
【解决方案2】:

如果您的框架代码有任何错误,那么浏览器将不会执行该代码并且它不会出现在您的网站中。所以,你应该首先确认框架是正确的。

你可以试试这个:

<div id="anyNameToFind">
  <span>here is the frame in website</span>
  <frame></frame>
</div>

但是,您应该首先检查您的工作天气。

【讨论】:

    【解决方案3】:

    我们遇到了这个问题,并最终通过先切换到 jqueryModalDialogsFrame 然后找到 scContentIframeId0 来解决这个问题。

    driver.SwitchTo().Frame("jqueryModalDialogsFrame");
    

    然后

    driver.SwitchTo().Frame("scContentIframeId0");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 2013-03-21
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 2014-01-06
      相关资源
      最近更新 更多