1+ // Licensed to the Software Freedom Conservancy (SFC) under one
2+ // or more contributor license agreements. See the NOTICE file
3+ // distributed with this work for additional information
4+ // regarding copyright ownership. The SFC licenses this file
5+ // to you under the Apache License, Version 2.0 (the
6+ // "License"); you may not use this file except in compliance
7+ // with the License. You may obtain a copy of the License at
8+ //
9+ // http://www.apache.org/licenses/LICENSE-2.0
10+ //
11+ // Unless required by applicable law or agreed to in writing,
12+ // software distributed under the License is distributed on an
13+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ // KIND, either express or implied. See the License for the
15+ // specific language governing permissions and limitations
16+ // under the License.
17+
18+
19+ using System ;
120using Microsoft . VisualStudio . TestTools . UnitTesting ;
21+ using OpenQA . Selenium ;
22+ using OpenQA . Selenium . Chrome ;
23+ using System . Collections . Generic ;
224
325namespace SeleniumDocs . Interactions
426{
5- [ TestClass ]
6- public class FramesTest : BaseTest
27+ [ TestClass ]
28+ public class FramesTest
729 {
30+ [ TestMethod ]
31+ public void TestFrames ( )
32+ {
33+ WebDriver driver = new ChromeDriver ( ) ;
34+ driver . Manage ( ) . Timeouts ( ) . ImplicitWait = TimeSpan . FromMilliseconds ( 500 ) ;
35+
36+ // Navigate to Url
37+ driver . Url = "https://www.selenium.dev/selenium/web/iframes.html" ;
38+ //switch To IFrame using Web Element
39+ IWebElement iframe = driver . FindElement ( By . Id ( "iframe1" ) ) ;
40+ //Switch to the frame
41+ driver . SwitchTo ( ) . Frame ( iframe ) ;
42+ Assert . AreEqual ( true , driver . PageSource . Contains ( "We Leave From Here" ) ) ;
43+ //Now we can type text into email field
44+ IWebElement emailE = driver . FindElement ( By . Id ( "email" ) ) ;
45+ emailE . SendKeys ( "[email protected] " ) ; 46+ emailE . Clear ( ) ;
47+ driver . SwitchTo ( ) . DefaultContent ( ) ;
48+
49+
50+ //switch To IFrame using name or id
51+ driver . FindElement ( By . Name ( "iframe1-name" ) ) ;
52+ //Switch to the frame
53+ driver . SwitchTo ( ) . Frame ( iframe ) ;
54+ Assert . AreEqual ( true , driver . PageSource . Contains ( "We Leave From Here" ) ) ;
55+ IWebElement email = driver . FindElement ( By . Id ( "email" ) ) ;
56+ //Now we can type text into email field
57+ email . SendKeys ( "[email protected] " ) ; 58+ email . Clear ( ) ;
59+ driver . SwitchTo ( ) . DefaultContent ( ) ;
60+
61+
62+ //switch To IFrame using index
63+ driver . SwitchTo ( ) . Frame ( 0 ) ;
64+ Assert . AreEqual ( true , driver . PageSource . Contains ( "We Leave From Here" ) ) ;
65+
66+ //leave frame
67+ driver . SwitchTo ( ) . DefaultContent ( ) ;
68+ Assert . AreEqual ( true , driver . PageSource . Contains ( "This page has iframes" ) ) ;
69+
70+ //quit the browser
71+ driver . Quit ( ) ;
72+ }
873 }
974}
0 commit comments