Skip to content

added frame code #2236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 1.35'
gem 'rubocop-rspec', '~> 3.0'
gem 'selenium-devtools', '= 0.133.0'
gem 'selenium-webdriver', '= 4.29.1'
gem 'selenium-devtools', '= 0.134.0'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traditionally exact versions can be provided just by doing '0.134.0' (Same below)

gem 'selenium-webdriver', '= 4.30.0'
35 changes: 35 additions & 0 deletions examples/ruby/spec/interactions/frames_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,40 @@
require 'spec_helper'

RSpec.describe 'Frames' do
#set session
let(:driver) { start_session }
let(:wait) { Selenium::WebDriver::Wait.new(timeout: 2) }

it 'interacts with elements inside iframes' do
#navigate to web page

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code comments might trip up IDE's as generally they have one space infront of the #

driver.navigate.to 'https://www.selenium.dev/selenium/web/iframes.html'
# Switch to iframe using WebElement
iframe = driver.find_element(id: 'iframe1')
driver.switch_to.frame(iframe)
expect(driver.page_source.include?('We Leave From Here')).to be true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(driver.page_source.include?('We Leave From Here')).to be true
expect(driver.page_source).to include('We Leave From Here')

Reason. RSpec exposes these booleans and it's a way of getting a better error message if it occurs


# Interact with email field
email_element = driver.find_element(id: 'email')
email_element.send_keys('admin@selenium.dev')
email_element.clear
driver.switch_to.default_content

# Switch to iframe using name
iframe=driver.find_element(name: 'iframe1-name')
driver.switch_to.frame(iframe)
expect(driver.page_source.include?('We Leave From Here')).to be true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(driver.page_source.include?('We Leave From Here')).to be true
expect(driver.page_source).to include('We Leave From Here')


email = driver.find_element(id: 'email')
email.send_keys('admin@selenium.dev')
email.clear
driver.switch_to.default_content

# Switch to iframe using index
driver.switch_to.frame(0)
expect(driver.page_source.include?('We Leave From Here')).to be true

# Leave frame
driver.switch_to.default_content
expect(driver.page_source.include?('This page has iframes')).to be true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,11 @@ driver.find_element(By.TAG_NAME, 'button').click()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Store iframe web element
iframe = driver.find_element(:css,'#modal > iframe')

# Switch to the frame
driver.switch_to.frame iframe
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L13-L22" >}}
{{< /tab >}}

# Now, Click on the button
driver.find_element(:tag_name,'button').click
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Store the web element
const iframe = driver.findElement(By.css('#modal > iframe'));
Expand Down Expand Up @@ -140,24 +135,12 @@ driver.find_element(By.TAG_NAME, 'button').click()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch by ID
driver.switch_to.frame 'buttonframe'

# Now, Click on the button
driver.find_element(:tag_name,'button').click
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Using the ID
await driver.switchTo().frame('buttonframe');

// Or using the name instead
await driver.switchTo().frame('myframe');
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L24-L32" >}}
{{< /tab >}}

// Now we can click the button
await driver.findElement(By.css('button')).click();
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< tab header="Kotlin" >}}
//Using the ID
driver.switchTo().frame("buttonframe")

Expand All @@ -181,13 +164,20 @@ queried using _window.frames_ in JavaScript.
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}}
{{< /tab >}}

{{< tab header="Ruby" >}}
# Switch to the second frame
driver.switch_to.frame(1)
{{< tab header="Python" >}}
# missing code

{{< /tab >}}

{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}

{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L34-L36" >}}
{{< /tab >}}


{{< tab header="JavaScript" >}}
// Switches to the second frame
await driver.switchTo().frame(1);
Expand Down Expand Up @@ -217,10 +207,11 @@ driver.switch_to.default_content()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Return to the top level
driver.switch_to.default_content
{{< /tab >}}

{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L38-L40" >}}
{{< /tab >}}

{{< tab header="JavaScript" >}}
// Return to the top level
await driver.switchTo().defaultContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,11 @@ driver.find_element(By.TAG_NAME, 'button').click()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Store iframe web element
iframe = driver.find_element(:css,'#modal > iframe')

# Switch to the frame
driver.switch_to.frame iframe
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L13-L22" >}}
{{< /tab >}}

# Now, Click on the button
driver.find_element(:tag_name,'button').click
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Store the web element
const iframe = driver.findElement(By.css('#modal > iframe'));
Expand Down Expand Up @@ -118,16 +113,24 @@ FrameまたはiFrameにidまたはname属性がある場合、代わりにこれ
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}}
{{< /tab >}}

{{< tab header="Python" >}}
# Switch frame by id
driver.switch_to.frame('buttonframe')

# Now, Click on the button
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}

{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
{{< /tab >}}

{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L24-L32" >}}
{{< /tab >}}


{{< tab header="JavaScript" >}}
// Using the ID
await driver.switchTo().frame('buttonframe');
Expand Down Expand Up @@ -158,20 +161,24 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch to the second frame
driver.switch_to.frame(1)
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}
{{< tab header="Python" >}}

{{< tab header="Python" >}}
# switching to second iframe based on index
iframe = driver.find_elements(By.TAG_NAME,'iframe')[1]

# switch to selected iframe
driver.switch_to.frame(iframe)
{{< /tab >}}

{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}

{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L34-L36" >}}
{{< /tab >}}


{{< tab header="JavaScript" >}}
// Switches to the second frame
await driver.switchTo().frame(1);
Expand All @@ -198,10 +205,11 @@ driver.switch_to.default_content()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Return to the top level
driver.switch_to.default_content
{{< /tab >}}

{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L38-L40" >}}
{{< /tab >}}

{{< tab header="JavaScript" >}}
// Return to the top level
await driver.switchTo().defaultContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,9 @@ driver.find_element(By.TAG_NAME, 'button').click()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Store iframe web element
iframe = driver.find_element(:css,'#modal > iframe')

# Switch to the frame
driver.switch_to.frame iframe

# Now, Click on the button
driver.find_element(:tag_name,'button').click
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L13-L22" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Store the web element
const iframe = driver.findElement(By.css('#modal > iframe'));
Expand Down Expand Up @@ -136,23 +129,12 @@ driver.find_element(By.TAG_NAME, 'button').click()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch by ID
driver.switch_to.frame 'buttonframe'

# Now, Click on the button
driver.find_element(:tag_name,'button').click
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Using the ID
await driver.switchTo().frame('buttonframe');

{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L24-L32" >}}
{{< /tab >}}

// Or using the name instead
await driver.switchTo().frame('myframe');

// Now we can click the button
await driver.findElement(By.css('button')).click();
{{< /tab >}}
{{< tab header="Kotlin" >}}
//Using the ID
driver.switchTo().frame("buttonframe")
Expand All @@ -174,20 +156,23 @@ consultado usando _window.frames_ em JavaScript.
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch to the second frame
driver.switch_to.frame(1)
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< tab header="Python" >}}
# switching to second iframe based on index
iframe = driver.find_elements(By.TAG_NAME,'iframe')[1]

# switch to selected iframe
driver.switch_to.frame(iframe)
{{< /tab >}}

{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}

{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L34-L36" >}}
{{< /tab >}}


{{< tab header="JavaScript" >}}
// Switches to the second frame
await driver.switchTo().frame(1);
Expand Down Expand Up @@ -215,10 +200,9 @@ driver.switch_to.default_content()
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Return to the top level
driver.switch_to.default_content
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples\ruby\spec\interactions\frames_spec.rb#L38-L40" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Return to the top level
await driver.switchTo().defaultContent();
Expand Down
Loading
Loading