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+
118package dev .selenium .interactions ;
219
3- import dev .selenium .BaseTest ;
20+ import org .junit .jupiter .api .Test ;
21+ import org .openqa .selenium .*;
22+ import org .openqa .selenium .chrome .ChromeDriver ;
23+ import java .time .Duration ;
24+ import static org .junit .jupiter .api .Assertions .assertEquals ;
25+
26+ public class FramesTest {
427
5- public class FramesTest extends BaseTest {
28+ @ Test
29+ public void informationWithElements () {
30+
31+ WebDriver driver = new ChromeDriver ();
32+ driver .manage ().timeouts ().implicitlyWait (Duration .ofMillis (500 ));
33+
34+ // Navigate to Url
35+ driver .get ("https://www.selenium.dev/selenium/web/iframes.html" );
36+
37+
38+ //switch To IFrame using Web Element
39+ WebElement iframe = driver .findElement (By .id ("iframe1" ));
40+ //Switch to the frame
41+ driver .switchTo ().frame (iframe );
42+ assertEquals (true , driver .getPageSource ().contains ("We Leave From Here" ));
43+ //Now we can type text into email field
44+ WebElement emailE = driver .findElement (By .id ("email" ));
45+ emailE .sendKeys ("admin@selenium.dev" );
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+ assertEquals (true , driver .getPageSource ().contains ("We Leave From Here" ));
55+ WebElement email =driver .findElement (By .id ("email" ));
56+ //Now we can type text into email field
57+ email .sendKeys ("admin@selenium.dev" );
58+ email .clear ();
59+ driver .switchTo ().defaultContent ();
60+
61+
62+ //switch To IFrame using index
63+ driver .switchTo ().frame (0 );
64+ assertEquals (true , driver .getPageSource ().contains ("We Leave From Here" ));
65+
66+ //leave frame
67+ driver .switchTo ().defaultContent ();
68+ assertEquals (true , driver .getPageSource ().contains ("This page has iframes" ));
69+
70+ //quit the browser
71+ driver .quit ();
72+ }
673
7- }
74+ }
0 commit comments