make link clickable

This commit is contained in:
Kanezoh 2021-08-19 11:08:49 +09:00
parent 48549dcaa2
commit 0736496335
3 changed files with 19 additions and 0 deletions

View File

@ -14,4 +14,12 @@ describe "Mechanize Page Link test" do
link = page.links.first
link.text.should eq "link text"
end
it "is clickable and returns page" do
agent = Mechanize.new
page = agent.get("http://example.com/link")
link = page.links.first
page = link.click
page.uri.to_s.should eq "http://example.com/"
end
end

View File

@ -113,4 +113,10 @@ class Mechanize
def max_history=(length)
history.max_size = length
end
# click link, and return page.
def click(link)
href = link.href
get href
end
end

View File

@ -12,4 +12,9 @@ class MechanizeCr::PageContent::Link
@href = node.fetch("href", "")
@text = node.inner_text
end
# click on this link
def click
@mech.click self
end
end