1
0
Fork 0
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:
Thomas Walpole 2016-10-26 12:24:51 -07:00
parent d4ea4bfb06
commit 54d7c0c9bb
4 changed files with 16 additions and 16 deletions

View file

@ -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')
```
@ -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')
```
@ -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] }
```
@ -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
```
@ -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
@ -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

View file

@ -18,7 +18,7 @@ module Capybara
# +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)
@ -155,7 +155,7 @@ module Capybara
# 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
@ -164,7 +164,7 @@ module Capybara
# 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:

View file

@ -263,7 +263,7 @@ module Capybara
# 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
#

View file

@ -52,7 +52,7 @@ RSpec.describe Capybara do
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')