【发布时间】: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&ro&la=en&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"> </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&ro&la=en&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 为Text、Url或Ok的元素。那么您能否详细说明您的问题.. -
附上框架内元素的 HTML 截图
-
好的,我已经提供了它作为答案,尝试一下,让我知道..
标签: c# selenium-webdriver modal-dialog sitecore sitecore7