Notice all the whitespace on the screen? That is where the empty name "" links are on the pp page output. Anyone have any ideas on how i can click one?
page = agent.page.link_with(:text => '').click
That line works for me. I put both of the following html pages in my local apache server's htdocs directory(a publicly accessible directory):
page1.html:
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<div><a href="/somesite.com/cat1.jpg">cat1</a></div>
<div><a href="/page2.html"></a></div>
<div><a href="/somesite.com/cat3.jpg"></a></div>
</body>
</html>
page2.html:
<!DOCTYPE html>
<html>
<head><title>Page2</title></head>
<body>
<div>hello</div>
</body>
</html>
Then I started up my server, which meant that page1.html was accessible in my browser using the url:
http://localhost:8080/page1.html
Then I ran the ruby program:
require 'mechanize'
agent = Mechanize.new
agent.get('http://localhost:8080/page1.html')
pp agent.page
page = agent.page.link_with(:text => '').click
puts page.title
...and the output was:
#<Mechanize::Page
{url #<URI::HTTP:0x00000100c8dc18 URL:http://localhost:8080/page1.html>}
{meta_refresh}
{title "Test"}
{iframes}
{frames}
{links
#<Mechanize::Page::Link "cat1" "/somesite.com/cat1.jpg">
#<Mechanize::Page::Link "" "/page2.html">
#<Mechanize::Page::Link "" "/somesite.com/cat3.jpg">}
{forms}>
Page2
The pp page output looks the same as your output, and I was successfully able to click on a link that has no text--as evidenced by the output Page2.
The only problem with that code is that that link_with() returns only the first match. If I use links_with(), I get all the matching links:
require 'mechanize'
agent = Mechanize.new
agent.get('http://localhost:8080/page1.html')
links = agent.page.links_with(:text => '')
p links
--output:--
[#<Mechanize::Page::Link "" "/page2.html">
, #<Mechanize::Page::Link "" "/somesite.com/cat3.jpg">
]
I would like to see the actual html of the links you are having problems with.