Having trouble using Capybara and Selenium to find an svg tag on a page Having trouble using Capybara and Selenium to find an svg tag on a page selenium selenium

Having trouble using Capybara and Selenium to find an svg tag on a page


It turns out this is an issue with Firefox's built in xpath evaluator.

Using FireBug, I was able to verify that the call that Selenium uses:

document.evaluate("//svg", document, null, 9, null).singleNodeValue

doesn't return any elements, whereas

document.evaluate("//div", document, null, 9, null).singleNodeValue

returns the first div on the page.

There may be some namespacing issues that could get FireFox to return svg elements. For now I've just looked for elements with my svg xmlns attribute.


I have found a solution which enables the use of CSS selectors:

scenario "there should be an SVG tag" do    ...    Nokogiri::HTML.parse(page.body).css('svg')end

Strange and annoying that it doesn't work out the box using page.find(), though.