Skip to content

Commit

Permalink
prefer .// over // in xpath examples
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Oct 26, 2016
1 parent d4ea4bf commit 54d7c0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -481,9 +481,9 @@ certain elements, and working with and manipulating those elements.

```ruby
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_content?('foo')
```
Expand All @@ -495,9 +495,9 @@ You can use these with RSpec's magic matchers:

```ruby
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_content('foo')
```
Expand All @@ -517,7 +517,7 @@ find_link(class: ['some_class', 'some_other_class'], :visible => :all).visible?
find_button('Send').click
find_button(value: '1234').click

find(:xpath, "//table/tr").click
find(:xpath, ".//table/tr").click
find("#overlay").find("h1").click
all('a').each { |a| a[:href] }
```
Expand Down Expand Up @@ -554,7 +554,7 @@ within("li#employee") do
fill_in 'Name', with: 'Jimmy'
end
within(:xpath, "//li[@id='employee']") do
within(:xpath, ".//li[@id='employee']") do
fill_in 'Name', with: 'Jimmy'
end
```
Expand Down Expand Up @@ -807,7 +807,7 @@ module MyModule
include Capybara::DSL

def login!
within(:xpath, "//form[@id='session']") do
within(:xpath, ".//form[@id='session']") do
fill_in 'Email', with: 'user@example.com'
fill_in 'Password', with: 'password'
end
Expand Down Expand Up @@ -892,16 +892,16 @@ and will always use CSS by default. If you want to use XPath, you'll need to
do:
```ruby
within(:xpath, '//ul/li') { ... }
find(:xpath, '//ul/li').text
find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
within(:xpath, './/ul/li') { ... }
find(:xpath, './/ul/li').text
find(:xpath, './/li[contains(.//a[@href = "#"]/text(), "foo")]').value
```
Alternatively you can set the default selector to XPath:
```ruby
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
Expand Down
6 changes: 3 additions & 3 deletions lib/capybara/node/finders.rb
Expand Up @@ -18,7 +18,7 @@ module Finders
# +find+ takes the same options as +all+.
#
# 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')
#
# @param (see Capybara::Node::Finders#all)
Expand Down Expand Up @@ -155,7 +155,7 @@ def find_by_id(id, options={}, &optional_filter_block)
# following statements are equivalent:
#
# 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
Expand All @@ -164,7 +164,7 @@ def find_by_id(id, options={}, &optional_filter_block)
# page.all("a#person_123")
#
# 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
# options. It's possible to select elements by their text or visibility:
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/session.rb
Expand Up @@ -263,7 +263,7 @@ def go_forward
# block, any command to Capybara will be handled as though it were scoped
# 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')
# end
#
Expand Down
2 changes: 1 addition & 1 deletion spec/basic_node_spec.rb
Expand Up @@ -52,7 +52,7 @@

it "allows using custom matchers" do
Capybara.add_selector :lifeform do
xpath { |name| "//option[contains(.,'#{name}')]" }
xpath { |name| ".//option[contains(.,'#{name}')]" }
end
expect(string).to have_selector(:id, "page")
expect(string).not_to have_selector(:id, 'does-not-exist')
Expand Down

0 comments on commit 54d7c0c

Please sign in to comment.