Selecting elements whose attribute begins with something in XPath

Allen Gingrich picture Allen Gingrich · Jul 21, 2010 · Viewed 49.3k times · Source

As the title says, is it possible to select elements in XPath that only begin with a certain string, but perhaps do not end with the same?

For example there are 3 anchor elements:

<a href="buy.php/onething"></a><a href="buy.php/twothing"></a><a href="sell.php/anotherthing"></a>

I only want to get anchor elements that begin with 'buy.php/'. I don't think the following will work, will it:

getByXPath("//a[@href='buy.php/']")

How can I do this?

Answer

MooGoo picture MooGoo · Jul 21, 2010