Skip to content

added code for frames ruby #2229

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
42 changes: 40 additions & 2 deletions examples/ruby/spec/interactions/frames_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@

require 'spec_helper'

RSpec.describe 'Frames' do
let(:driver) { start_session }
RSpec.describe 'Frames Test' do
it 'interacts with elements inside iframes' do
driver = Selenium::WebDriver.for :chrome
driver.manage.timeouts.implicit_wait = 0.5

# Navigate to URL
driver.get('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

# 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
driver.find_element(name: 'iframe1-name')
driver.switch_to.frame(iframe)
expect(driver.page_source.include?('We Leave From Here')).to be true

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

# Quit the browser
driver.quit
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