简体   繁体   English

c# Selenium:无法切换到模态/弹出窗口/iFrame

[英]c# Selenium: Unable to SwitchTo Modal/Pop-up/iFrame

Testing a web app using c# selenium.使用 c# selenium 测试 web 应用程序。

Having logged in, we proceed through the application until clicking a button, a modal window appears.登录后,我们继续执行应用程序,直到单击一个按钮,出现一个模态 window。

We have tried (we think,) every possible option, to carry on the test on this modal window!我们已经尝试(我们认为)所有可能的选项,在这个模态窗口上进行测试!

<iframe id="if_OpenModalDialog" style="width: 1024px; height: 768px;"></iframe> is the result of Inspect. <iframe id="if_OpenModalDialog" style="width: 1024px; height: 768px;"></iframe>是 Inspect 的结果。

We've tried, among others:我们已经尝试过,其中包括:

1 driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("iframe[name='#if_OpenModalDialog']"))); 1 driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("iframe[name='#if_OpenModalDialog']")));

2 driver.SwitchTo().Frame("if_OpenModalDialog"); 2 driver.SwitchTo().Frame("if_OpenModalDialog");

3 driver.SwitchTo().Frame(0); 3 driver.SwitchTo().Frame(0);

4 driver.SwitchTo().Window("various names"); 4 driver.SwitchTo().Window("various names");

Also tried WindowHandles but with no luck.还尝试了 WindowHandles 但没有运气。

Error messages either that the frame cannot be found or that the first element on the modal cannot be found (we've tried several locating methods.).无法找到框架或无法找到模态框上的第一个元素的错误消息(我们已经尝试了几种定位方法。)。

The error for method 1 above gives OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"iframe[name='#if_OpenModalDialog']"}上面方法 1 的错误给出了OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"iframe[name='#if_OpenModalDialog']"}

I'd really appreciate ANY ideas before I go completely around the bend!!!在我 go 完全绕弯之前,我真的很感激任何想法!

Thanks谢谢

@KunduK has asked for the page source - I can't do the whole thing as it exceeds this site's limits but I hope what's below is OK. @KunduK 已要求提供页面源 - 我无法完成所有操作,因为它超出了本网站的限制,但我希望下面的内容可以。

 </div> <input type="submit" name="ModalDialog$btn_DummyUC" value="[Lang?]btn_DummyUC" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ModalDialog$btn_DummyUC&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, 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(&quot;ModalDialog$btn_CloseModalDialogUC&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, 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&amp;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':'mm','ss 'GMT'":"ShortDatePattern":"dd/MM/yyyy","ShortTimePattern":"HH:mm":"SortableDateTimePattern","yyyy'-'MM'-'dd'T'HH':'mm':'ss","TimeSeparator":":":"UniversalSortableDateTimePattern","yyyy'-'MM'-'dd HH':'mm','ss'Z'":"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>

Here's the actual code of the test - we've tried various sleep times... driver.SwitchTo().Frame("Main");这是测试的实际代码 - 我们尝试了各种睡眠时间... 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);


    }

The line home3.AddBookingLine.Click();home3.AddBookingLine.Click(); triggers the modal...触发模态...

单击添加以触发弹出窗口

模态

Your css selector seems incorrect.您的 css 选择器似乎不正确。 Try with this.试试这个。 cssselectror for id should be tagname#attributeval or only #attributeval id的 cssselectror 应该是tagname#attributeval或只有#attributeval

driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("iframe#if_OpenModalDialog")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM