mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
prefer .// over // in xpath examples
This commit is contained in:
parent
d4ea4bfb06
commit
54d7c0c9bb
4 changed files with 16 additions and 16 deletions
22
README.md
22
README.md
|
@ -481,9 +481,9 @@ certain elements, and working with and manipulating those elements.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
page.has_selector?('table tr')
|
page.has_selector?('table tr')
|
||||||
page.has_selector?(:xpath, '//table/tr')
|
page.has_selector?(:xpath, './/table/tr')
|
||||||
|
|
||||||
page.has_xpath?('//table/tr')
|
page.has_xpath?('.//table/tr')
|
||||||
page.has_css?('table tr.foo')
|
page.has_css?('table tr.foo')
|
||||||
page.has_content?('foo')
|
page.has_content?('foo')
|
||||||
```
|
```
|
||||||
|
@ -495,9 +495,9 @@ You can use these with RSpec's magic matchers:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
expect(page).to have_selector('table tr')
|
expect(page).to have_selector('table tr')
|
||||||
expect(page).to have_selector(:xpath, '//table/tr')
|
expect(page).to have_selector(:xpath, './/table/tr')
|
||||||
|
|
||||||
expect(page).to have_xpath('//table/tr')
|
expect(page).to have_xpath('.//table/tr')
|
||||||
expect(page).to have_css('table tr.foo')
|
expect(page).to have_css('table tr.foo')
|
||||||
expect(page).to have_content('foo')
|
expect(page).to have_content('foo')
|
||||||
```
|
```
|
||||||
|
@ -517,7 +517,7 @@ find_link(class: ['some_class', 'some_other_class'], :visible => :all).visible?
|
||||||
find_button('Send').click
|
find_button('Send').click
|
||||||
find_button(value: '1234').click
|
find_button(value: '1234').click
|
||||||
|
|
||||||
find(:xpath, "//table/tr").click
|
find(:xpath, ".//table/tr").click
|
||||||
find("#overlay").find("h1").click
|
find("#overlay").find("h1").click
|
||||||
all('a').each { |a| a[:href] }
|
all('a').each { |a| a[:href] }
|
||||||
```
|
```
|
||||||
|
@ -554,7 +554,7 @@ within("li#employee") do
|
||||||
fill_in 'Name', with: 'Jimmy'
|
fill_in 'Name', with: 'Jimmy'
|
||||||
end
|
end
|
||||||
|
|
||||||
within(:xpath, "//li[@id='employee']") do
|
within(:xpath, ".//li[@id='employee']") do
|
||||||
fill_in 'Name', with: 'Jimmy'
|
fill_in 'Name', with: 'Jimmy'
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
@ -807,7 +807,7 @@ module MyModule
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
|
||||||
def login!
|
def login!
|
||||||
within(:xpath, "//form[@id='session']") do
|
within(:xpath, ".//form[@id='session']") do
|
||||||
fill_in 'Email', with: 'user@example.com'
|
fill_in 'Email', with: 'user@example.com'
|
||||||
fill_in 'Password', with: 'password'
|
fill_in 'Password', with: 'password'
|
||||||
end
|
end
|
||||||
|
@ -892,16 +892,16 @@ and will always use CSS by default. If you want to use XPath, you'll need to
|
||||||
do:
|
do:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
within(:xpath, '//ul/li') { ... }
|
within(:xpath, './/ul/li') { ... }
|
||||||
find(:xpath, '//ul/li').text
|
find(:xpath, './/ul/li').text
|
||||||
find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
|
find(:xpath, './/li[contains(.//a[@href = "#"]/text(), "foo")]').value
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively you can set the default selector to XPath:
|
Alternatively you can set the default selector to XPath:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
Capybara.default_selector = :xpath
|
Capybara.default_selector = :xpath
|
||||||
find('//ul/li').text
|
find('.//ul/li').text
|
||||||
```
|
```
|
||||||
|
|
||||||
Capybara allows you to add custom selectors, which can be very useful if you
|
Capybara allows you to add custom selectors, which can be very useful if you
|
||||||
|
|
|
@ -18,7 +18,7 @@ module Capybara
|
||||||
# +find+ takes the same options as +all+.
|
# +find+ takes the same options as +all+.
|
||||||
#
|
#
|
||||||
# page.find('#foo').find('.bar')
|
# page.find('#foo').find('.bar')
|
||||||
# page.find(:xpath, '//div[contains(., "bar")]')
|
# page.find(:xpath, './/div[contains(., "bar")]')
|
||||||
# page.find('li', text: 'Quox').click_link('Delete')
|
# page.find('li', text: 'Quox').click_link('Delete')
|
||||||
#
|
#
|
||||||
# @param (see Capybara::Node::Finders#all)
|
# @param (see Capybara::Node::Finders#all)
|
||||||
|
@ -155,7 +155,7 @@ module Capybara
|
||||||
# following statements are equivalent:
|
# following statements are equivalent:
|
||||||
#
|
#
|
||||||
# page.all(:css, 'a#person_123')
|
# page.all(:css, 'a#person_123')
|
||||||
# page.all(:xpath, '//a[@id="person_123"]')
|
# page.all(:xpath, './/a[@id="person_123"]')
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# If the type of selector is left out, Capybara uses
|
# If the type of selector is left out, Capybara uses
|
||||||
|
@ -164,7 +164,7 @@ module Capybara
|
||||||
# page.all("a#person_123")
|
# page.all("a#person_123")
|
||||||
#
|
#
|
||||||
# Capybara.default_selector = :xpath
|
# Capybara.default_selector = :xpath
|
||||||
# page.all('//a[@id="person_123"]')
|
# page.all('.//a[@id="person_123"]')
|
||||||
#
|
#
|
||||||
# The set of found elements can further be restricted by specifying
|
# The set of found elements can further be restricted by specifying
|
||||||
# options. It's possible to select elements by their text or visibility:
|
# options. It's possible to select elements by their text or visibility:
|
||||||
|
|
|
@ -263,7 +263,7 @@ module Capybara
|
||||||
# block, any command to Capybara will be handled as though it were scoped
|
# block, any command to Capybara will be handled as though it were scoped
|
||||||
# to the given element.
|
# to the given element.
|
||||||
#
|
#
|
||||||
# within(:xpath, '//div[@id="delivery-address"]') do
|
# within(:xpath, './/div[@id="delivery-address"]') do
|
||||||
# fill_in('Street', with: '12 Main Street')
|
# fill_in('Street', with: '12 Main Street')
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
|
|
@ -52,7 +52,7 @@ RSpec.describe Capybara do
|
||||||
|
|
||||||
it "allows using custom matchers" do
|
it "allows using custom matchers" do
|
||||||
Capybara.add_selector :lifeform do
|
Capybara.add_selector :lifeform do
|
||||||
xpath { |name| "//option[contains(.,'#{name}')]" }
|
xpath { |name| ".//option[contains(.,'#{name}')]" }
|
||||||
end
|
end
|
||||||
expect(string).to have_selector(:id, "page")
|
expect(string).to have_selector(:id, "page")
|
||||||
expect(string).not_to have_selector(:id, 'does-not-exist')
|
expect(string).not_to have_selector(:id, 'does-not-exist')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue