How to detect mailto links with Hpricot/Nokogiri - ruby

I want to match links like foo, but this doesn't work only works in Nokogiri:
doc/'a[href ^="mailto:"]'
What's the right way of doing that? How do I do that with Hpricot?

doc/"//a[starts-with(#href,'mailto')]"

This works on Hpricot:
doc/'a[#href ^="mailto:"]'
Couldn't figure out a way to do the xpath search though. Apparently, Hpricot doesn't support starts-with: http://wiki.github.com/hpricot/hpricot/supported-xpath-expressions

Related

How to write xpath for below code displayed on Image

Snapshots displayed Field as well as Inspect element code. Always faced problem on writing xpath for table element. Xpath copied from Moxilla firbugs is worked sometimes but not always.. can any one tell how to write xpath of above code.... Thanks
You can use this xpath
//table[#class='detailList']/tbody/tr/td[contains(text(),'Business Lease')]

How to locate an element having href='#' attribute in anchor tag

abc
I am not able to locate above element. I tried //*[#id="contact-groups"], but with no success.
Well, XPath is not the best of the methods to find elements. But following will match the links with href = "#".
//a[#href="#"]
Not sure if your scenario is as simple as your question. I did test this with a simple html page.
The locator seems correct. You could try this too:
.//*[#id='contact-groups']
As per HTML code provided you can try below xpaths
//a[#id='contact-groups']
//a[contains(text(),'abc')]
//a[#href='#']
Thanks
I am guessing the link is in an Iframe.
Use the following code to switch to the frame and then click on the link
driver.switchTo().frame("frame-name");
driver.findElement(By.xpath("//a[#id='contact-groups']")).click();

Cannot narrow down an xpath using mechanize in ruby to extract a table

I'm trying to get the data contained after this highlighted td tag:
(screenshot taken from firefox developer tools)
but I don't understand how I'm going to get there. I tried to use xpath
page.parser.xpath("//table//tbody//tr//td//ul//form//table//tbody//tr/td")
but this doesn't work and I assuming it's because I'm not identifying anything? I am not sure how I'm going to identify stuff though, since some of them have no ids or names. So the question is how do I reach this tag.
Probably because the tbody isn't really there. There's a lot of discussion on SO about that particular issue.
Here's how what I would probably do:
td = page.at '#tF0 .txt2'

xpath for a google search url issue no content

http://www.google.com/search?q=youtube
Trying to get the url part www.youtube.com/ of the search
using this xpath but there is no output from it.
.//*[#id='rso']/li[1]/div/div[2]/div[1]/cite
i've also tried using the css path same issue
CSS: div[aria-label='Result details']+div>div cite.
Btw, your xpath works fine for me. If you use selenium to retrieve your text for example, you should write xpath=.// in this case, because it recognize selector as xpath by preceding // symbols. Also //*[#id='rso']/li[1]/div/div[2]/div[1]/cite//text() will return three textNodes www., youtube and .com/

Capybara: Link with HTML content not found

Given a HTML structure like this
<strong>My Link</strong>
is not caught by Capybara through a cucumber step
When I follow "My Link"
using a default webstep
When /^(?:|I )follow "([^"]*)"$/ do |link|
click_link(link)
end
while this works:
When I follow "<strong>My Link</strong>"
I haven't been using Capbybara for long, but I can see what causes the problem. So, on a more general level — what's the proper way to go about this? Surely this case has to be pretty common, right?
Any ideas and general musings about Cucumber abuse very welcome!
I would move strong tag outside anchor tag or better use CSS for that.
Or you can assign id attribute to link and use it instead of content. This way is the best if your app supports multiple languages.
Otherwise you have to write some sort of xpath selector for such special case:
find(:xpath, "//a[contains(//text(), \"#{locator}\")]").click
Not tested, just an idea.

Resources