Skip to content

[rb] Update finders examples and move them #1800

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

Merged
merged 3 commits into from
Jul 9, 2024
Merged
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
35 changes: 35 additions & 0 deletions examples/ruby/spec/elements/finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,39 @@

RSpec.describe 'Element Finders' do
let(:driver) { start_session }

context 'without executing finders', skip: 'these are just examples, not actual tests' do
it 'finds the first matching element' do
driver.find_element(class: 'tomatoes')
end

it 'uses a subset of the dom to find an element' do
fruits = driver.find_element(id: 'fruits')
fruit = fruits.find_element(class: 'tomatoes')
end

it 'uses an optimized locator' do
fruit = driver.find_element(css: '#fruits .tomatoes')
end

it 'finds all matching elements' do
plants = driver.find_elements(tag_name: 'li')
end

it 'gets an element from a collection' do
elements = driver.find_elements(:tag_name,'p')
elements.each { |e| puts e.text }
end

it 'finds element from element' do
element = driver.find_element(:tag_name,'div')
elements = element.find_elements(:tag_name,'p')
elements.each { |e| puts e.text }
end

it 'find active element' do
driver.find_element(css: '[name="q"]').send_keys('webElement')
attr = driver.switch_to.active_element.attribute('title')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ vegetable = driver.find_element(By.CLASS_NAME, "tomatoes")
{{< tab header="CSharp" >}}
var vegetable = driver.FindElement(By.ClassName("tomatoes"));
{{< /tab >}}
{{< tab header="Ruby" >}}
vegetable = driver.find_element(class: 'tomatoes')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L14-L15">}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const vegetable = await driver.findElement(By.className('tomatoes'));
{{< /tab >}}
Expand Down Expand Up @@ -87,10 +87,9 @@ fruit = fruits.find_element(By.CLASS_NAME,"tomatoes")
IWebElement fruits = driver.FindElement(By.Id("fruits"));
IWebElement fruit = fruits.FindElement(By.ClassName("tomatoes"));
{{< /tab >}}
{{< tab header="Ruby" >}}
fruits = driver.find_element(id: 'fruits')
fruit = fruits.find_element(class: 'tomatoes')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L14-L15">}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const fruits = await driver.findElement(By.id('fruits'));
const fruit = fruits.findElement(By.className('tomatoes'));
Expand Down Expand Up @@ -131,9 +130,9 @@ fruit = driver.find_element(By.CSS_SELECTOR,"#fruits .tomatoes")
{{< tab header="CSharp" >}}
var fruit = driver.FindElement(By.CssSelector("#fruits .tomatoes"));
{{< /tab >}}
{{< tab header="Ruby" >}}
fruit = driver.find_element(css: '#fruits .tomatoes')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L19" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const fruit = await driver.findElement(By.css('#fruits .tomatoes'));
{{< /tab >}}
Expand Down Expand Up @@ -161,9 +160,9 @@ plants = driver.find_elements(By.TAG_NAME, "li")
{{< tab header="CSharp" >}}
IReadOnlyList<IWebElement> plants = driver.FindElements(By.TagName("li"));
{{< /tab >}}
{{< tab header="Ruby" >}}
plants = driver.find_elements(tag_name: 'li')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L23" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const plants = await driver.findElements(By.tagName('li'));
{{< /tab >}}
Expand Down Expand Up @@ -227,23 +226,9 @@ namespace FindElementsExample {
}
}
{{< /tab >}}
{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
begin
# Navigate to URL
driver.get 'https://www.example.com'

# Get all the elements available with tag name 'p'
elements = driver.find_elements(:tag_name,'p')

elements.each { |e|
puts e.text
}
ensure
driver.quit
end
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L27-L28" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const {Builder, By} = require('selenium-webdriver');
(async function example() {
Expand Down Expand Up @@ -359,26 +344,9 @@ namespace FindElementsFromElement {
}
}
{{< /tab >}}
{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
begin
# Navigate to URL
driver.get 'https://www.example.com'

# Get element with tag name 'div'
element = driver.find_element(:tag_name,'div')

# Get all the elements available with tag name 'p'
elements = element.find_elements(:tag_name,'p')

elements.each { |e|
puts e.text
}
ensure
driver.quit
end
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L32-L34" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const {Builder, By} = require('selenium-webdriver');

Expand Down Expand Up @@ -484,19 +452,8 @@ It is used to track (or) find DOM element which has the focus in the current bro
}
}
{{< /tab >}}
{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
begin
driver.get 'https://www.google.com'
driver.find_element(css: '[name="q"]').send_keys('webElement')

# Get attribute of current active element
attr = driver.switch_to.active_element.attribute('title')
puts attr
ensure
driver.quit
end
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L38-L39" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const {Builder, By} = require('selenium-webdriver');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ vegetable = driver.find_element(By.CLASS_NAME, "tomatoes")
{{< tab header="CSharp" >}}
var vegetable = driver.FindElement(By.ClassName("tomatoes"));
{{< /tab >}}
{{< tab header="Ruby" >}}
vegetable = driver.find_element(class: 'tomatoes')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L10" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const vegetable = await driver.findElement(By.className('tomatoes'));
{{< /tab >}}
Expand Down Expand Up @@ -81,10 +81,9 @@ fruit = fruits.find_element(By.CLASS_NAME,"tomatoes")
IWebElement fruits = driver.FindElement(By.Id("fruits"));
IWebElement fruit = fruits.FindElement(By.ClassName("tomatoes"));
{{< /tab >}}
{{< tab header="Ruby" >}}
fruits = driver.find_element(id: 'fruits')
fruit = fruits.find_element(class: 'tomatoes')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L14-L15" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const fruits = await driver.findElement(By.id('fruits'));
const fruit = fruits.findElement(By.className('tomatoes'));
Expand Down Expand Up @@ -121,9 +120,9 @@ fruit = driver.find_element(By.CSS_SELECTOR,"#fruits .tomatoes")
{{< tab header="CSharp" >}}
var fruit = driver.FindElement(By.CssSelector("#fruits .tomatoes"));
{{< /tab >}}
{{< tab header="Ruby" >}}
fruit = driver.find_element(css: '#fruits .tomatoes')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L19" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const fruit = await driver.findElement(By.css('#fruits .tomatoes'));
{{< /tab >}}
Expand All @@ -150,9 +149,9 @@ plants = driver.find_elements(By.TAG_NAME, "li")
{{< tab header="CSharp" >}}
IReadOnlyList<IWebElement> plants = driver.FindElements(By.TagName("li"));
{{< /tab >}}
{{< tab header="Ruby" >}}
plants = driver.find_elements(tag_name: 'li')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L23" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const plants = await driver.findElements(By.tagName('li'));
{{< /tab >}}
Expand Down Expand Up @@ -214,23 +213,9 @@ namespace FindElementsExample {
}
}
{{< /tab >}}
{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
begin
# Navigate to URL
driver.get 'https://www.example.com'

# Get all the elements available with tag name 'p'
elements = driver.find_elements(:tag_name,'p')

elements.each { |e|
puts e.text
}
ensure
driver.quit
end
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L27-L28" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const {Builder, By} = require('selenium-webdriver');
(async function example() {
Expand Down Expand Up @@ -345,26 +330,9 @@ namespace FindElementsFromElement {
}
}
{{< /tab >}}
{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
begin
# Navigate to URL
driver.get 'https://www.example.com'

# Get element with tag name 'div'
element = driver.find_element(:tag_name,'div')

# Get all the elements available with tag name 'p'
elements = element.find_elements(:tag_name,'p')

elements.each { |e|
puts e.text
}
ensure
driver.quit
end
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L32-L34" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const {Builder, By} = require('selenium-webdriver');

Expand Down Expand Up @@ -469,19 +437,8 @@ namespace FindElementsFromElement {
}
}
{{< /tab >}}
{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
begin
driver.get 'https://www.google.com'
driver.find_element(css: '[name="q"]').send_keys('webElement')

# Get attribute of current active element
attr = driver.switch_to.active_element.attribute('title')
puts attr
ensure
driver.quit
end
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="/examples/ruby/spec/elements/finders_spec.rb#L38-L39" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
const {Builder, By} = require('selenium-webdriver');
Expand Down
Loading
Loading