首页 > 解决方案 > Katalon Studio 找不到 svg 标签来创建对象

问题描述

我正在尝试创建一个用于拖放的对象,但我没有为嵌套在 svg 标签内的图像创建对象。Katalon 能找到 svg 标签吗?

我可以在我的网络应用程序上找到图像,但当它嵌套在 svg 标记中时则不行。

<svg class="enyo-svg image" id="application_mainView_FileViewerPanel_control16_projectView1_Frame"
 preserveAspectRatio="none" version="1.1"xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink" style="width: 532.7px; height: 355.13px;">

<image id="application_mainView_FileViewerPanel_control16_projectView1_Image" 
xlink:href="assets/images/projects/centroCivico.svg" x="0" y="0" 
width="100%" height="100%" preserveAspectRatio="xMidYMid meet" style=""></image></svg>

标签: htmltestingsvgui-testingkatalon-studio

解决方案


github上有这样的讨论:https ://github.com/kazurayam/KatalonDiscussion4977 。

对于此处SVG可用的基本应用程序,我们尝试访问的元素的 HTML是

<html>
<body>
  <div id="hs-component">
    <div class="container">
      <div id="wrap">
        ...
        <div class="... demo">
          ...
          <div class="chart-container">
            <div id="container">
              <div id="highcharts-0x1te9k-0">
                <svg xmlns="http://http://www.w3.org/2000/svg" ...>
                  ...
                  <text class="highcharts-title">
                    <tspan>Solar Employment Growth by Sector, 2010-2016</tspan>
                  </text>
                  ...
                </svg>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

以下XPath选择器不起作用:

//div[@id="container"]/div/svg

Katalon 发出警告

com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/Page_Basic line/svg_namespace-ignorant' located by 'By.xpath: //div[@id="container"]/div/svg' not found

XPath需要命名空间感知

可以通过以下方式选择具有 Namespace-uri http://www.w3.org/2000/svgXPath的 svg 节点:

//div[@id="container"]/div/*[namespace-uri() = "http://www.w3.org/2000/svg" and local-name()="svg"]

但是,目标文档恰好只有一个名为“svg”的节点,因此您可以放宽谓词省略条件 namespace-uri()="..." 。以下XPath表达式也有效:

//div[@id="container"]/div/*[local-name()="svg"]

最后,您可以SVG通过以下XPath表达式选择文本节点:

//div[@id="container"]/div/*[local-name()="svg"]/*[local-name()="text" and @class="highcharts-title"]

请,看看它是否有帮助。


推荐阅读