Skip to main content
 首页 » 编程设计

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

2024年12月31日9leader

我想基于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]