require File.expand_path("spec_helper", File.dirname(__FILE__)) describe Watir::ElementLocator do include LocatorSpecHelper describe "finds a single element" do describe "by delegating to webdriver" do WEBDRIVER_SELECTORS.each do |loc| it "delegates to webdriver's #{loc} locator" do expect_one(loc, "bar").and_return(element(:tag_name => "div")) locate_one loc => "bar" end end end describe "with selectors not supported by webdriver" do it "handles selector with tag name and a single attribute" do expect_one :xpath, ".//div[@class='foo']" locate_one :tag_name => "div", :class => "foo" end it "handles selector with no tag name and and a single attribute" do expect_one :xpath, ".//*[@title='foo']" locate_one :title => "foo" end it "handles single quotes in the attribute string" do expect_one :xpath, %{.//*[@title=concat('foo and ',"'",'bar',"'",'')]} locate_one :title => "foo and 'bar'" end it "handles selector with tag name and multiple attributes" do expect_one :xpath, ".//div[@class='foo' and @title='bar']" locate_one [:tag_name, "div", :class , "foo", :title , 'bar'] end it "handles selector with no tag name and multiple attributes" do expect_one :xpath, ".//*[@class='foo' and @title='bar']" locate_one [:class, "foo", :title, "bar"] end end describe "with special cased selectors" do it "normalizes space for :text" do expect_one :xpath, ".//div[normalize-space()='foo']" locate_one :tag_name => "div", :text => "foo" end it "translates :caption to :text" do expect_one :xpath, ".//div[normalize-space()='foo']" locate_one :tag_name => "div", :caption => "foo" end it "translates :class_name to :class" do expect_one :xpath, ".//div[@class='foo']" locate_one :tag_name => "div", :class_name => "foo" end it "handles data-* attributes" do expect_one :xpath, ".//div[@data-name='foo']" locate_one :tag_name => "div", :data_name => "foo" end it "normalizes space for the :href attribute" do expect_one :xpath, ".//a[normalize-space(@href)='foo']" selector = { :tag_name => "a", :href => "foo" } locate_one selector, Watir::Anchor.attributes end it "uses the corresponding