[英]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.