spec/watirspec/elements/element_spec.rb in watir-6.10.3 vs spec/watirspec/elements/element_spec.rb in watir-6.11.0.beta1

- old
+ new

@@ -197,19 +197,16 @@ it "raises UnknownObjectException exception if the element does not exist" do expect { browser.text_field(id: "no_such_id").visible? }.to raise_unknown_object_exception end it "raises UnknownObjectException exception if the element is stale" do - wd_element = browser.text_field(id: "new_user_email").wd + element = browser.text_field(id: "new_user_email").tap(&:exists?) - # simulate element going stale during lookup - allow(browser.driver).to receive(:find_element).with(:css, '#new_user_email') { wd_element } - allow(browser.driver).to receive(:find_elements).with(:css, '#new_user_email') { [wd_element] } - allow(browser.driver).to receive(:find_elements).with(:tag_name, 'iframe') { [] } browser.refresh - expect { browser.text_field(css: '#new_user_email').visible? }.to raise_unknown_object_exception + expect(element).to be_stale + expect { element.visible? }.to raise_unknown_object_exception end it "returns true if the element has style='visibility: visible' even if parent has style='visibility: hidden'" do expect(browser.div(id: "visible_child")).to be_visible end @@ -293,9 +290,25 @@ end it "finds element by attribute absence" do expect(browser.p(data_type: false)).not_to exist expect(browser.p(class: false)).to exist + end + end + + context ":index locator" do + before { browser.goto WatirSpec.url_for("data_attributes.html") } + + it "finds the first element by index: 0" do + expect(browser.element(index: 0).tag_name).to eq "html" + end + + it "finds the second element by index: 1" do + expect(browser.element(index: 1).tag_name).to eq "head" + end + + it "finds the last element by index: -1" do + expect(browser.element(index: -1).tag_name).to eq "p" end end it "doesn't raise when called on nested elements" do expect(browser.div(id: 'no_such_div').link(id: 'no_such_id')).to_not exist