python - 从悬停元素获取定位器

标签 python selenium selenium-webdriver xpath css-selectors

我想获取这个元素的定位器(5,126, 第601章 601)但似乎无法正常获取。

我认为必须将鼠标悬停在该元素上并尝试获取 xpath,但我仍然无法将鼠标悬停在其中,因为它是一个 SVG 元素。有人知道一种正确获取定位器的方法吗?
这是网站链接:https://fundingsocieties.com/progress

enter image description here

最佳答案

嗯,这个元素只能通过将鼠标悬停在图表上来更新。
这是该元素的唯一 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/

相关文章:

python - 是否有支持 AWS ElastiCache 的自动发现功能的 Python Memcached 库?

python - 如何在 ipywidgets Python 的选项卡中显示 interact()

python - 什么是 python 的 useAutomationExtension for selenium?

python - 等到一个元素被激活, Selenium

python - 在python中进行全页截图而不分页

selenium-webdriver - IE11 Selenium WebDriverException:导航失败。 (org.openqa.selenium.WebDriverException ...IWebBrowser2::Navigate2() 失败

python - 使用 Python 进行图像裁剪

python - django.core.exceptions 在 python 中运行 selenium 功能测试时出现 ImproperlyConfigured 错误

python + Selenium webdriver : using authenticate method

python - 为什么在 apache 上找不到 python 模块