|  | 
|  | 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 | +# Unless required by applicable law or agreed to in writing, | 
|  | 11 | +# software distributed under the License is distributed on an | 
|  | 12 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
|  | 13 | +# KIND, either express or implied.  See the License for the | 
|  | 14 | +# specific language governing permissions and limitations | 
|  | 15 | +# under the License. | 
|  | 16 | + | 
|  | 17 | + | 
| 1 | 18 | # frozen_string_literal: true | 
| 2 | 19 | 
 | 
| 3 | 20 | require 'spec_helper' | 
| 4 | 21 | 
 | 
| 5 | 22 | RSpec.describe 'Frames' do | 
| 6 | 23 |   let(:driver) { start_session } | 
|  | 24 | + | 
|  | 25 | +  it 'performs iframe switching operations' do | 
|  | 26 | +    # Set firefox and launch web page | 
|  | 27 | +    driver = Selenium::WebDriver.for :firefox | 
|  | 28 | +    driver.get("https://www.selenium.dev/selenium/web/iframes.html") | 
|  | 29 | +    # --- Switch to iframe using WebElement --- | 
|  | 30 | +    iframe = driver.find_element(:id, "iframe1") | 
|  | 31 | +    driver.switch_to.frame(iframe) | 
|  | 32 | +    expect(driver.page_source).to include("We Leave From Here") | 
|  | 33 | +     | 
|  | 34 | +    email_element = driver.find_element(:id, "email") | 
|  | 35 | +    email_element.send_keys("[email protected]") | 
|  | 36 | +    email_element.clear | 
|  | 37 | +    driver.switch_to.default_content | 
|  | 38 | + | 
|  | 39 | +    # --- Switch to iframe using name or ID --- | 
|  | 40 | +    iframe1 = driver.find_element(:name, "iframe1-name")  # (This line doesn't switch, just locates) | 
|  | 41 | +    driver.switch_to.frame(iframe) | 
|  | 42 | +    expect(driver.page_source).to include("We Leave From Here") | 
|  | 43 | +     | 
|  | 44 | +    email = driver.find_element(:id, "email") | 
|  | 45 | +    email.send_keys("[email protected]") | 
|  | 46 | +    email.clear | 
|  | 47 | +    driver.switch_to.default_content | 
|  | 48 | + | 
|  | 49 | +    # --- Switch to iframe using index --- | 
|  | 50 | +    driver.switch_to.frame(0) | 
|  | 51 | +    expect(driver.page_source).to include("We Leave From Here") | 
|  | 52 | + | 
|  | 53 | +    # --- Final page content check --- | 
|  | 54 | +    driver.switch_to.default_content | 
|  | 55 | +    expect(driver.page_source).to include("This page has iframes") | 
|  | 56 | +     | 
|  | 57 | +    # Quit the driver | 
|  | 58 | +    driver.quit | 
|  | 59 | +  end | 
| 7 | 60 | end | 
0 commit comments