使用Capybara和Selenium在页面上查找svg标签时遇到问题 [英] Having trouble using Capybara and Selenium to find an svg tag on a page

查看:95
本文介绍了使用Capybara和Selenium在页面上查找svg标签时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的测试用例:

I had a test case like this:

  scenario "there should be an SVG tag" do
    ...
    page.find("svg")
  end

由于某种原因,即使我在页面的源中查看时,水豚也找不到svg标记.

For some reason, Capybara could not find the svg tag even though when I looked in the page's source, the tag was there (and also visually).

在执行以下操作后,我才能够找到SVG标签:

I was only able to get it to find the SVG tag after I did something like:

  scenario "there should be an SVG tag" do
    ...
    page.find("#layers *[xmlns='http://www.w3.org/2000/svg']")
  end

(请注意,svg在图层" ID中).

(Note, the svg is within the "layers" ID).

有人有什么想法吗?我使用Selenium作为驱动程序.

Does anyone have any ideas? I use Selenium as the driver.

推荐答案

事实证明,这是Firefox内置的xpath评估程序存在的问题.

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

使用FireBug,我能够验证Selenium使用的呼叫:

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

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

不返回任何元素,而

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

返回页面上的第一个div.

returns the first div on the page.

可能存在一些命名间隔问题,这些问题可能会使FireFox返回svg元素.现在,我只是在寻找具有svg xmlns属性的元素.

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.

这篇关于使用Capybara和Selenium在页面上查找svg标签时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆