Ruby 在Watir webdriver中测试svg图表

Ruby 在Watir webdriver中测试svg图表,ruby,testing,svg,automation,watir-webdriver,Ruby,Testing,Svg,Automation,Watir Webdriver,我正在测试一张图表是否有正确的标题“收入”。我正在使用watir webdriver自动化这些测试 HTML代码: <nvd3-multi-bar-chart data="chartData" id="revenueChart" class="chart-render ng-isolate-scope" showxaxis="true" showyaxis="true" color="colorFunction()" interactive="true" xaxistickformat="

我正在测试一张图表是否有正确的标题“收入”。我正在使用watir webdriver自动化这些测试

HTML代码:

<nvd3-multi-bar-chart data="chartData" id="revenueChart" class="chart-render ng-isolate-scope" showxaxis="true" showyaxis="true" color="colorFunction()" interactive="true" xaxistickformat="xAxisTickFormat()" yaxistickformat="yAxisTickFormat()" yaxisshowmaxmin="false" callback="chartCreatedCallbackFunction()" nodata="">
<text x="20" y="20" text-anchor="start" class="statistics-title">Revenue</text>
<text x="20" y="40" text-anchor="start" class="statistics-title-total">Total: 1,222,140 USD</text>

据我所知,尝试以下方式:

   if @browser.element(:xpath, '//*[@id="revenueChart"]/svg/text[0]').text == 'Revenue'
        print_green('Revenue Chart title --- Pass')
    end

下面是一个使用
元素
定位器的非xpath替代方案:

if b.element(class: "statistics-title").text == "Revenue"
  # your message here
end

谢谢,但是我得到了并且找不到元素错误:找不到元素,使用{:xpath=>“/*[@id=\“revenueChart\”]/svg/te xt[1]”}(Watir::Exception::UnknownObjectException)@Ahsan让我们尝试一下:
@browser.elements(:xpath,/*[@id=“revenueChart”]/svg/text')。最后。text
找不到元素,使用{:xpath=>“/*[@id=\'revenueChart\']/svg/te xt”,:index=>-1}(Watir::Exception::UnknownObjectException)
if b.element(class: "statistics-title").text == "Revenue"
  # your message here
end