使用c# selenium测试web应用程序。
登录后,我们继续浏览应用程序,直到单击一个按钮,出现一个模式窗口。
我们已经尝试过了(我们认为!)每个可能的选项,在这个模式窗口上进行测试!
<iframe id="if_OpenModalDialog" style="width: 1024px; height: 768px;"></iframe>是检查的结果。
我们已经尝试过了,其中包括:
1个driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("iframe[name='#if_OpenModalDialog']")));
2个driver.SwitchTo().Frame("if_OpenModalDialog");
3个driver.SwitchTo().Frame(0);
4个driver.SwitchTo().Window("various names");
我也尝试过WindowHandles,但没有成功。
错误消息要么是找不到框架,要么是找不到模式上的第一个元素(我们已经尝试了几种定位方法!)。
上面方法1的错误给出了OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"css selector","selector":"iframe[name='#if_OpenModalDialog']"}
在我完全发疯之前,我真的很感激任何想法!
谢谢
@KunduK已经要求提供页面源代码-我不能做整个事情,因为它超出了这个网站的限制,但我希望下面的内容是可以的。
</div>
<input type="submit" name="ModalDialog$btn_DummyUC" value="[Lang?]btn_DummyUC" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ModalDialog$btn_DummyUC", "", true, "", "", false, false))" id="ModalDialog_btn_DummyUC" class="Hide" />
<div id="ModalDialog_mp_OpenModalDialogUC" class="modalPopup openModalDialog">
<div class="header">
<input type="image" name="ModalDialog$btn_CloseModalDialogUC" id="ModalDialog_btn_CloseModalDialogUC" class="showImg" src="../../Images/Close.svg" onclick="ModalDialogUCReturnValue();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ModalDialog$btn_CloseModalDialogUC", "", true, "", "", false, false))" />
</div>
<iframe id="ModalDialog_if_OpenModalDialogUC"></iframe>
</div>
<div id="pi_Progress_pnl_PIwrapper" class="progressIndicatorWrapper">
<div id="pi_Progress_up_PI" style="visibility:hidden;display:block;">
<div class="ModalUpdateProgress"></div>
<div id="pi_Progress_pnl_PI" class="ProgressUpdate">
<span id="pi_Progress_lblMessage" class="Label">Processing. Please Wait...</span>
<br />
<br />
<img id="pi_Progress_img_Processing" class="ProgressUpdate" src="../../Images/Logo-White.svg" alt="" />
</div>
</div>
</div>
<input type="hidden" name="_IG_CSS_LINKS_" id="_IG_CSS_LINKS_" value="/rezlynx1500/WebResource.axd?d=Ub3U1EM5FpAN0E8JfdsLjzYQpC_AJjXO9yVqg56RXuhxBuC6fJghDZ6WKdjccrIqLCtvmJrVMnzcZLXaIoKeU2Y_aw6HQEoT_HGwfodiPrlh4C4PgYj7z9nayVjVqWeyXou9iN6w2Cap9Xm-_fgBEtRcVvik_JLlx4If9mZCUo7J7gDu0&t=637533988920000000|../../Styles/AppStyling/ig_monthcalendar.css|../../Styles/AppStyling/ig_texteditor.css|../../Styles/AppStyling/ig_dropDown.css|../../Styles/AppStyling/ig_shared.css" />
<script type="text/javascript">
//<![CDATA[
var Page_Validators = new Array(document.getElementById("rev_Delegates"), document.getElementById("ctl29"), document.getElementById("ctl30"), document.getElementById("ctl31"), document.getElementById("ctl32"), document.getElementById("ctl33"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var rev_Delegates = document.all ? document.all["rev_Delegates"] : document.getElementById("rev_Delegates");
rev_Delegates.controltovalidate = "winp_Delegates";
rev_Delegates.display = "Dynamic";
rev_Delegates.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
rev_Delegates.validationexpression = "^[1-9][0-9]*$";
var ctl29 = document.all ? document.all["ctl29"] : document.getElementById("ctl29");
ctl29.controltovalidate = "winp_Nights";
ctl29.focusOnError = "t";
ctl29.errormessage = "Nights is mandatory";
ctl29.display = "Dynamic";
ctl29.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl29.initialvalue = "";
var ctl30 = document.all ? document.all["ctl30"] : document.getElementById("ctl30");
ctl30.controltovalidate = "winp_Nights";
ctl30.focusOnError = "t";
ctl30.errormessage = "Nights must be greater than zero";
ctl30.display = "Dynamic";
ctl30.type = "Double";
ctl30.decimalchar = ".";
ctl30.evaluationfunction = "CompareValidatorEvaluateIsValid";
ctl30.valuetocompare = "0";
ctl30.operator = "GreaterThan";
var ctl31 = document.all ? document.all["ctl31"] : document.getElementById("ctl31");
ctl31.controltovalidate = "winp_Adults";
ctl31.focusOnError = "t";
ctl31.errormessage = "Adults must be numeric";
ctl31.display = "Dynamic";
ctl31.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
ctl31.validationexpression = "^-?((\\d+)|(\\d+\\.\\d+)|(\\.\\d+))$";
var ctl32 = document.all ? document.all["ctl32"] : document.getElementById("ctl32");
ctl32.controltovalidate = "winp_Children";
ctl32.focusOnError = "t";
ctl32.errormessage = "Children must be numeric";
ctl32.display = "Dynamic";
ctl32.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
ctl32.validationexpression = "^-?((\\d+)|(\\d+\\.\\d+)|(\\.\\d+))$";
var ctl33 = document.all ? document.all["ctl33"] : document.getElementById("ctl33");
ctl33.controltovalidate = "winp_Infants";
ctl33.focusOnError = "t";
ctl33.errormessage = "Infants must be numeric";
ctl33.display = "Dynamic";
ctl33.evaluationfunction = "RegularExpressionValidatorEvaluateIsValid";
ctl33.validationexpression = "^-?((\\d+)|(\\d+\\.\\d+)|(\\.\\d+))$";
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
URLProfileSearch='/rezlynx1500/RLXWebForms/pro/wfrm_pro_Search.aspx'; URLCompanySearch='/rezlynx1500/RLXWebForms/com/wfrm_com_Search.aspx';NumberOfDecimalPlaces=2; NumberGroupSeparator=','; NumberDecimalSeparator='.'; MoneyDecimalPlaces=4;RegisterStayDates('dpwinp_ArrivalDate','winp_Nights','dpwinp_DepartureDate');
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
if (typeof(FixAjaxControls) == "function") FixAjaxControls();Sys.Application.add_init(function() {
$create(Infragistics.Web.UI.WebDatePicker, {"id":"dpwinp_ArrivalDate","name":"dpwinp_ArrivalDate","props":[[[],{"c":{"prop1":"[\"2021-3-7-0-0-0-0,,\",\"09/05/03\",\"_ 0322\",\"09/05/03\",29,0,\"clwinp_ArrivalDate\",\"\",\"0,3,0,3,0,0,3,0,3,0\"]","vse":0,"prop":"1,0,,0,1,1,,,0,,,,,6,,200,,2038:2040:2032,igte_AppStylingFocus,igte_AppStylingHover,igte_AppStylingNullText,igte_AppStylingInnerFocus,igte_AppStylingInnerHover","uid":"dpwinp_ArrivalDate","buts":"igte_AppStylingButtonHover,igte_AppStylingButtonPressed,igte_AppStylingButtonDisabled,igte_AppStylingButtonFocus,../../Styles/AppStyling/images/igte_customHover.gif,../../Styles/AppStyling/images/igte_customPress.gif,../../Styles/AppStyling/images/igte_customDisable.gif,"}}],,,["TextChanged:gl_UpdateDepartureDate","ValueChanged:gl_UpdateDepartureDate"]]}, null, null, $get("dpwinp_ArrivalDate"));
});
Sys.Application.add_init(function() {
$create(Infragistics.Web.UI.WebMonthCalendar, {"id":"clwinp_ArrivalDate","name":"clwinp_ArrivalDate","props":[[[],{"c":{"str":"January,February,March,April,May,June,July,August,September,October,November,December,","uid":"clwinp_ArrivalDate","tday":"8=Today: 09/04/2021=Today: 07/04/2021=Today: {0:d}","tdyDateTimeFormat":{"AMDesignator":"AM","Calendar":{"MinSupportedDateTime":"\/Date(-62135596800000)\/","MaxSupportedDateTime":"\/Date(253402300799999)\/","AlgorithmType":1,"CalendarType":1,"Eras":[1],"TwoDigitYearMax":2029,"IsReadOnly":false},"DateSeparator":"/","FirstDayOfWeek":1,"CalendarWeekRule":2,"FullDateTimePattern":"dd MMMM yyyy HH:mm:ss","LongDatePattern":"dd MMMM yyyy","LongTimePattern":"HH:mm:ss","MonthDayPattern":"d MMMM","PMDesignator":"PM","RFC1123Pattern":"ddd, dd MMM yyyy HH\u0027:\u0027mm\u0027:\u0027ss \u0027GMT\u0027","ShortDatePattern":"dd/MM/yyyy","ShortTimePattern":"HH:mm","SortableDateTimePattern":"yyyy\u0027-\u0027MM\u0027-\u0027dd\u0027T\u0027HH\u0027:\u0027mm\u0027:\u0027ss","TimeSeparator":":","UniversalSortableDateTimePattern":"yyyy\u0027-\u0027MM\u0027-\u0027dd HH\u0027:\u0027mm\u0027:\u0027ss\u0027Z\u0027","YearMonthPattern":"MMMM yyyy","AbbreviatedDayNames":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"ShortestDayNames":["Su","Mo","Tu","We","Th","Fr","Sa"],"DayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"AbbreviatedMonthNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthNames":["January","February","March","April","May","June","July","August","September","October","November","December",""],"IsReadOnly":false,"NativeCalendarName":"Gregorian Calendar","AbbreviatedMonthGenitiveNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthGenitiveNames":["January","February","March","April","May","June","July","August","September","October","November","December",""]},"vse":0,"anim":"500,3,300,3,0,200,3,100,3,0","dates":"2021,4,1500,1,1,2500,12,31,0","myp":"## %","img":"../../Styles/AppStyling/images/igmc_prevHover.gif,../../Styles/AppStyling/images/igmc_prevPress.gif,../../Styles/AppStyling/images/igmc_nextHover.gif,../../Styles/AppStyling/images/igmc_nextPress.gif","prop":"15,3,7,2,0,1,0,0,1,1,1,2038,2040,2039,2037,2036,,,6,5,igmc_AppStylingDay,igmc_AppStylingWeekendDay,igmc_AppStylingOtherMonthDay,igmc_AppStylingTodayDay,igmc_AppStylingSelectedDay,igmc_AppStylingWeekNumber,igmc_AppStylingHoverDay,igmc_AppStylingFocusDay,igmc_AppStylingDisabledDay,igmc_AppStylingHoverNextPrev,igmc_AppStylingPressedNextPrev,igmc_AppStylingHoverMonthYear,igmc_AppStylingPressedMonthYear,igmc_AppStylingHoverFooter,igmc_AppStylingPressedFooter,igmc_AppStylingList,igmc_AppStylingItem,igmc_AppStylingHoverItem,igmc_AppStylingSelectedItem,"}}],,,[]]}, null, null, $get("clwinp_ArrivalDate"));
});
document.getElementById('rev_Delegates').dispose = function() {
Array.remove(Page_Validators, document.getElementById('rev_Delegates'));
}
document.getElementById('ctl29').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ctl29'));
}
document.getElementById('ctl30').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ctl30'));
}
Sys.Application.add_init(function() {
$create(Infragistics.Web.UI.WebDatePicker, {"id":"dpwinp_DepartureDate","name":"dpwinp_DepartureDate","props":[[[],{"c":{"prop1":"[\"2021-3-8-0-0-0-0,,\",\"09/05/03\",\"_ 0322\",\"09/05/03\",29,0,\"clwinp_ArrivalDate\",\"\",\"0,3,0,3,0,0,3,0,3,0\"]","vse":0,"prop":"1,0,,0,1,1,,,0,,,,,6,,200,,2038:2040:2032,igte_AppStylingFocus,igte_AppStylingHover,igte_AppStylingNullText,igte_AppStylingInnerFocus,igte_AppStylingInnerHover","uid":"dpwinp_DepartureDate","buts":"igte_AppStylingButtonHover,igte_AppStylingButtonPressed,igte_AppStylingButtonDisabled,igte_AppStylingButtonFocus,../../Styles/AppStyling/images/igte_customHover.gif,../../Styles/AppStyling/images/igte_customPress.gif,../../Styles/AppStyling/images/igte_customDisable.gif,"}}],,,["TextChanged:gl_UpdateNoOfNights","ValueChanged:gl_UpdateNoOfNights"]]}, null, null, $get("dpwinp_DepartureDate"));
});
document.getElementById('ctl31').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ctl31'));
}
document.getElementById('ctl32').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ctl32'));
}
document.getElementById('ctl33').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ctl33'));
}
Sys.Application.add_init(function() {
$create(Infragistics.Web.UI.WebDropDown, {"id":"msd_HideWhenRestrictedBy_wdd_Property","name":"wdd_Property","props":[[[,,200,,,,,,,,,1,0,,,,,,0,,,0,,"",,,,,,1,,,0,,,,,,,,,,0,,,,,,,,],{"c":{"dropDownInputClass":"igdd_AppStylingValueDisplay","dropDownInputDisabledClass":"ig_AppStylingDisabled igdd_AppStylingValueDisplayDisabled","dropDownButtonDisabledImageUrl":"../../Styles/AppStyling/images/igdd_DropDownButtonDisabled.png","dropDownItemSelected":"igdd_AppStylingListItemSelected","dropDownItemDisabled":"igdd_AppStylingListItemDisabled","_pi":"[\"../../Styles/AppStyling/images/ig_ajaxIndicator.gif\",,,\"ig_AppStylingAjaxIndicator\",,1,,,,\"ig_AppStylingAjaxIndicatorBlock\",,3,,3,\"Async post\"]","chkAT":"Checked","dropDownInputFocusClass":"igdd_AppStylingValueDisplayFocus","dropDownButtonHoverImageUrl":"../../Styles/AppStyling/images/ig_dropdownbutton_hover.gif","dropDownButtonNormalImageUrl":"../../Styles/AppStyling/images/ig_dropdownbutton.gif","dropDownButtonPressedImageUrl":"../../Styles/AppStyling/images/ig_dropdownbutton_press.gif","dropDownItemHover":"igdd_AppStylingListItemHover","controlClass":"ig_AppStylingControl igdd_AppStylingControl","ocs":1,"pi":"[]","nullTextCssClass":"igdd_AppStylingNullText","dropDownInputHoverClass":"ig_AppStylingHover igdd_AppStylingValueDisplayHover","unchkAT":"Unchecked","pageCount":0,"controlAreaClass":"igdd_AppStylingControlArea","controlAreaFocusClass":"igdd_AppStylingControlFocus","dropDownButtonClass":"igdd_AppStylingDropDownButton","dropDownItemClass":"igdd_AppStylingListItem","dropDownItemActiveClass":"igdd_AppStylingListItemActive","controlDisabledClass":"ig_AppStylingDisabled igdd_AppStylingControlDisabled","uid":"msd_HideWhenRestrictedBy$wdd_Property","controlAreaHoverClass":"ig_AppStylingHover igdd_AppStylingControlHover"}}],,[{'0':[[,,,,,"Ceilings","10",,,,]],'1':[[,,,,,"Promo Code","20",,,,]],'2':[[,,,,,"User Access","30",,,,]],'3':[[,,,,,"Length of Stay","40",,,,]],'4':[[,,,,,"Occupants","50",,,,]],'5':[[163986,,,,,"Yield Management","60",,,,]],'6':[[,,,,,"Other Reasons","70",,,,]]}],["ValueChanged:WebDropDownValueChanged"]]}, null, null, $get("msd_HideWhenRestrictedBy_wdd_Property"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.ModalPopupBehavior, {"backgroundCssClass":"modalBackground","cancelControlID":"ModalDialog_btn_CloseModalDialogUC","dynamicServicePath":"/rezlynx1500/RLXWebForms/pak/wfrm_pak_PackageSearch.aspx","id":"mpeUC","popupControlID":"ModalDialog_mp_OpenModalDialogUC"}, null, null, $get("ModalDialog_btn_DummyUC"));
});
Sys.Application.add_init(function() {
$create(Sys.UI._UpdateProgress, {"associatedUpdatePanelId":null,"displayAfter":0,"dynamicLayout":false}, null, null, $get("pi_Progress_up_PI"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.AlwaysVisibleControlBehavior, {"horizontalSide":1,"id":"pi_Progress_avce","verticalSide":1}, null, null, $get("pi_Progress_pnl_PIwrapper"));
});
//]]>
</script>
</form>
</body>
</html>
这是测试的实际代码-我们尝试了不同的睡眠时间...driver.SwitchTo().Frame("Main");
POM_CreateRes home3 = new POM_CreateRes(driver);
//CreateReservation
home3.AddBookingLine.Click();
System.Threading.Thread.Sleep(3000);
//driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("iframe#ModalDialog_mp_OpenModalDialogUC")));
driver.SwitchTo().Frame("ModalDialog_if_OpenModalDialogUC");
System.Threading.Thread.Sleep(2000);
home3.Modal.Click();
// home3.RatePlanSearch.Click();
System.Threading.Thread.Sleep(1000);
}home3.AddBookingLine.Click();这一行触发了模式...


发布于 2021-04-07 22:48:03
您的css选择器似乎不正确。试试这个。id的cssselectror应为tagname#attributeval或仅为#attributeval
driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("iframe#if_OpenModalDialog")));https://stackoverflow.com/questions/66988383
复制相似问题