python - svg 的 xpath,无法根据路径属性定位

标签 python selenium svg selenium-webdriver xpath

我想基于SVG定位图标。 Xpath 不工作。区分这两个图标的唯一方法是使用此属性,但这不起作用。

<path d="M8 5v14l11-7z"

我试过:

//*[name()='svg']/*[name()='path' and @d="M8 5v14l11-7z"] 

没有运气

<div class="page-details-box-links ng-scope" style="">
            <button class="icon-style >
                <div c style="">
                    <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" style="">
                        <path d="M8 5v14l11-7z" style=""></path>
                        <path d="M0 0h24v24H0z" fill="none" style=""></path>
                    </svg>
                </div>
                <div  style="">Run job</div>
            </button>
            <button style="">
                <div  style="">
                    <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" style="">
                        <path d="M0 0h24v24H0z" fill="none" style=""></path>
                        <path d="M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z" style=""></path>
                    </svg>
                </div>
                <div class="cv-material-button-tooltip" style="">Edit</div>
            </button>
        </div>

最佳答案

试试这个 xpath :

//button[contains(@class,'con-styl')]//*[name()='svg']/*[1]

关于python - svg 的 xpath,无法根据路径属性定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50993054/

相关文章:

java - Selenium Java 中的 setAttribute a href

java - 如何从 Hoover 菜单 Selenium JAVA 打开 WebElement

vue.js - Vue - 维特 |静态 svg Assets

svg - 将SVG多边形转换为路径

python - 如何使用值对字典进行排序并能够访问键

python - 我如何使用 python 将输出打印到 html 页面?

python - 使用一个已经打开的网页(带 Selenium )到 beautifulsoup?

html - 如何使 svg 中的线条位置响应

c# - 有没有办法将 C# 序列化对象读入 Python?

python - 从 Python 或 R 中的文件名列表中提取子字符串