简体   繁体   English

无法使用XPATH在Selenium中选择SVG中的元素

[英]Unable to select element in SVG with Selenium using XPATH

I am trying to extract data from an SVG chart using selenium. 我正在尝试使用硒从SVG图表中提取数据。 The XPATH seems correct as with an xpath helper wizard I retrieve the value, but running a Python script it returns an empty value... XPATH似乎是正确的,因为我使用xpath辅助向导来检索该值,但是运行Python脚本会返回一个空值...

Here is a part of the code 这是代码的一部分

<svg width="710" height="184">
    <g>
        <g class="sub _0">
            <g>
                <circle cla ss="dot xh-highlight" r="0" fill="#3887DD" cx="0" cy="117.55757575757576" style="fill-opacity: 1e-06; stroke-opacity: 1e-06;">
                    <title class="">Tue Feb 09 2016 01:00:00 GMT+0100 (CET): 120</title>
                </circle>
                <circle class="dot" r="0" fill="#3887DD" cx="0.8892086330935252" cy="117.34121212121212" style="fill-opacity: 1e-06; stroke-opacity: 1e-0;">
                    <title class="">Wed Feb 10 2016 01:00:00 GMT+0100 (CET): 138</title>
                </circle>
            </g>
        </g>
    </g>
</svg>

and the Selenium code 和硒代码

LaunchDate = driver.find_elements_by_xpath("//*[name()='svg']/*[name()='g']/*[contains(@class ,'_0')]//*[name()='circle'][1]").text

Does anyone Know what goes wrong ? 有谁知道出了什么问题?

Thanks 谢谢

Your html has an error, an extra space in the word class of the first circle. 您的html出现错误,第一个圆圈的单词类中有多余的空格。

i this this should work to get the first circle: 我这应该工作以获得第一个圈子:

//svg//g[contains(@class,"_0")]//circle[contains(@class,"highlight")]

i hope it helps :) 我希望它会有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 select 元素使用 xpath 使用 selenium - unable to select an element using xpath using selenium 无法在 selenium 和 Z23EEEB4347BDD26BFC6B7EE9A3B75 中使用 xpath 的元素 select - unable to select an element using xpath in selenium and python 无法通过 xpath 使用 Selenium 和 Python 定位元素 - Unable to locate element by xpath using Selenium with Python 使用 selenium 无法通过 xpath 找到元素 - Unable to find element by xpath using selenium 无法在 selenium 中使用 xpath 定位表元素 - Unable to locate table element using xpath in selenium 无法使用 xpath 使用 python 和 selenium 定位元素 - Unable to locate element with xpath using python and selenium Select Selenium、Python 中的一个元素,而不是使用 ZB6454D4986313710A1891ZED1CEA - Select an element in Selenium, Python, not by using XPath 尝试使用Selenium通过xpath选择元素,但出现错误“无法找到元素” - Trying to select element by xpath with Selenium but getting error “Unable to locate element” 无法通过Selenium Webdriver python中的XPath选择元素 - Unable to select an element via XPath in selenium Webdriver python 无法在Python中使用Selenium从下拉菜单中通过xpath选择元素 - Unable to select element by xpath from dropdown menu with Selenium in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM