Watin Framework Learning two--processing of pop-up windows

Source: Internet
Author: User

Take IE as an example, Watin processing pop-up windows:

1ie ie =NewIE ("string");//Open the specified Web page2Ie. Button (Find.byid ("string")). Click ();//Click the appropriate button to pop up the window you want to test Testsecondwindow3ie Newie = ie. Attachto<ie> (Find.bytitle ("Testsecondwindow"));//Find new Window Testsecondwindow and assign to new IE object4             //Todo:write The code need to test in Newie
View Code

Watin Processing Confirm dialog box:

1ie ie =NewIE (string);//Open the specified Web page2Confirmdialoghandler CDH =NewConfirmdialoghandler ();3Ie. Adddialoghandler (CDH);//associating an Confirmdialoghandler object with IE4Ie. Button (Find.byid (string)). Clicknowait ();//Remember to use clicknowait instead of click, otherwise the code will not continue until the modal window is closed. 5 CDH. Waituntilexists ();6 CDH. Okbutton.click (); 7 ie. Waitforcomplete ();8Ie. Removedialoghandler (CDH);//Confirmdialoghandler object associated with IE unlink
View Code

The point to note here is the difference between the click () method and the Clicknowait () method, first look at the Click () method

1         /// <summary>2         ///Clicks This element and waits till the event are completely finished (page is loaded3         ///and ready ).4         /// </summary>5          Public Virtual voidClick ()6         {7Clickimpl (true);8}
View Code

Next is the Clicknowait () method:

1         /// <summary>2         ///Clicks This instance and returns immediately. Use this method when you want to continue without waiting3         ///For the Click event to be finished. Mostly used when a4         ///htmldialog or JavaScript popup is a displayed after clicking the element.5         /// </summary>6          Public Virtual voidclicknowait ()7         {8Clickimpl (false);9}
View Code

From the above two pieces of code, you can see that they all call the Clickimpl (bool xxx) method, but a true one is false, then the definition of the bool value is what? Find the Clickimpl () method:

1         /// <summary>2         ///Handles the implementation of Click and clicknowait3         /// </summary>4         protected Virtual voidClickimpl (BOOLwaitforcomplete)5         {6             if(!Enabled)7             {8                 Throw NewElementdisabledexception (Idorname, This);9             }Ten  OneLogger.logaction ((logfunction log) = {log ("clicking (no wait) {0} ' {1} ', {2}", GetType (). Name, Idorname, Description); }); A  -Highlight (true); -  the             if(Waitforcomplete) -             { -FireEvent ("onclick"); -             } +             Else -             { +Fireeventnowait ("onclick"); A             } at  -             Try -             { -                 if(Waitforcomplete) waitforcomplete (); -             } -             finally in             { -Highlight (false); to             } +}
View Code

The original bool value represents Waitforcomplete, leaving aside the other code, first to find the following judgment statement:

1             if(Waitforcomplete)2             {3FireEvent ("onclick");4             }5             Else6             {7Fireeventnowait ("onclick");8}
View Code

The problem turns into the difference between the FireEvent () method and the Fireeventnowait () method, first finding the FireEvent () method:

1         /// <summary>2         ///Fires The specified<paramref name= "EventName"/>On this element3         ///And waits for it to complete.4         /// </summary>5         /// <param name= "EventName" >Name of the event.</param>6          Public Virtual voidFireEvent (stringeventName)7         {8FireEvent (EventName,true,NULL);9}
View Code

See this code, want to, and fireeventnowait () the difference between the method may also be one of the bool value difference, sure enough, see Fireeventnowait () Method:

1         /// <summary>2         ///Only fires the specified<paramref name= "EventName"/>On the This element.3         /// </summary>4          Public Virtual voidFireeventnowait (stringeventName)5         {6FireEvent (EventName,false,NULL);7}
View Code

Both of these methods are called fireevent (string xxx, bool xxx,?) method, and the difference is only the bool value of the setting, regardless, skip to this method to see first:

1         Private voidFireEvent (stringEventName,BOOLWaitforcomplete, NameValueCollection eventproperties)2         {3             if(!Enabled)4             {5                 Throw NewElementdisabledexception (Idorname, This);6             }7 8Highlight (true);9 Ten             if(Waitforcomplete) One             { A nativeelement.fireevent (EventName, eventproperties); - Waitforcomplete (); -             } the             Else -             { - nativeelement.fireeventnowait (EventName, eventproperties); -             } +  -Highlight (false); +}
View Code

Here you will find that the emphasis is on the following code:

 1  if   (waitforcomplete)  2   { 3   Nativeelement.fireevent (EventName, eventproperties);  4   Waitforcomplete ();  5   6
      else   { 8   nativeelement.fi Reeventnowait (EventName, eventproperties);  9 } 
View Code

And the main thing is on the Waitforcomplete () method call, that is, the clicknowait () method on the side of the comment on the note, if the Click () method, the code will go down before the window must wait for the mode to close, Once closed is Waitforcomplete () completed, so using the Click () method, the surface looks like the entire program will stop moving, thus not working on the dialog box.

Watin Framework Learning two--processing of pop-up windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.