【发布时间】:2020-03-11 21:23:07
【问题描述】:
/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[4]/div[1]/div[1]/div[5]/div[1]/div[*]/div[2] --
这个 XPath 给了我 4 个 div 标签,我在这里扩展了最后 2 个标签。这些基本上是 4 行,如果行包含值,我必须依次单击它会弹出 并且值将打印在控制台上,否则必须在控制台上打印的行上写的内容。
这里的第 2 行和第 4 行 (div) 的文字是“请稍候....”。
第三个 div 标签包含 91%,我可以获取
使用//*[name()='svg']//*[name()='g'][1]//*[name()='text'] 并打印在控制台上。但是很难获取文本“请稍候...”。来自 div 标签。
这里是 4 div 标签代码
<div class="custom- slick-cell l1 r1" style="" xpath="1"></div>
<div class="custom- slick-cell l1 r1" style="" xpath="2"></div>
<div class="custom- slick-cell l1 r1 active selected" style="" xpath="3">
<svg width="100%" height="25" version="1.1" id="SVG_c0784e89-a155-4a07-b7d1-8236510dd78c" data-ispopupdisplayallowed="true" data-measureid="486" data-is-pcp-user="false" data-is-po-user="true" onclick="openEPSDTCompletionRateSummary('SVG_c0784e89-a155-4a07-b7d1-8236510dd78c')" xmlns="http://www.w3.org/2000/svg">
<g></g>
<text x="10" y="17" fill="black" style="font-weight: bolder; font-size: 12px;" id="PopUp_c0784e89-a155-4a07-b7d1-8236510dd78c">
91%
</text>
<g></g>
</svg>
</div>
<div class="custom- slick-cell l1 r1" xpath="4">
<svg width="100%" height="25" version="1.1" id="SVG_f4f7f3fb-b09d-4c26-ac2f-81e01172416f" data-ispopupdisplayallowed="false" data-measureid="500" data-is-pcp-user="false" data-is-po-user="true" xmlns="http://www.w3.org/2000/svg">
<g></g>
<text x="10" y="17" fill="black" style="font-weight: bolder; font-size: 12px;" id="PopUp_f4f7f3fb-b09d-4c26-ac2f-81e01172416f">
Please wait....
</text>
<g></g>
</svg>
</div>
【问题讨论】:
-
我不确定你的 xpath
//*[name()='svg']//*[name()='g'][1]//*[name()='text']与你的 html sn-p 有什么关系,因为你没有不为空的<g>组(至少在你提供的代码中)跨度> -
这个 xpath 应该识别元素
Please wait....并且 Xpath 是//div[@class='custom- slick-cell l1 r1']//*[name()='svg']//*[name()='text']
标签: selenium