我想获取这个元素的定位器(5,126, 第601章 601)但似乎无法正常获取。
我认为必须将鼠标悬停在该元素上并尝试获取 xpath,但我仍然无法将鼠标悬停在其中,因为它是一个 SVG 元素。有人知道一种正确获取定位器的方法吗?
这是网站链接:https://fundingsocieties.com/progress
最佳答案
嗯,这个元素只能通过将鼠标悬停在图表上来更新。
这是该元素的唯一 XPath 定位器:
"//*[name()='text']//*[name()='tspan' and(contains(@style,'bold'))]"
整个 Selenium 命令可以是:
total_text = driver.find_element(By.XPATH, "//*[name()='text']//*[name()='tspan' and(contains(@style,'bold'))]").text
这也可以通过 CSS 选择器来完成:text tspan[style*='bold']
,因此 Selenium 命令可以是
total_text = driver.find_element(By.CSS_SELECTOR, "text tspan[style*='bold']").text
嗯,CSS 选择器看起来短多了:)
关于python - 从悬停元素获取定位器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74355834/