擅长:python、mysql、java
<p>我不完全确定您正在尝试执行哪些操作,但假设您已经将鼠标悬停在某个点上,要获取文本,请使用以下命令:</p>
<p>要仅获取<code>USD to EUR:</code>文本,请使用:</p>
<pre><code>driver.find_elements_by_css_selector(".highcharts-label.highcharts-tooltip-box.highcharts-color-0>text[data-z-index]>tspan:nth-of-type(1)")
</code></pre>
<p>要获取货币值,请使用:</p>
<pre><code>driver.find_elements_by_css_selector(".highcharts-tooltip-box.highcharts-color-0>text[data-z-index]>tspan:nth-of-type(2)")
</code></pre>
<p>注意,在第二个定位器中,我删除了一个类,定位器仍然是唯一的</p>
<p>因此,方法是使用悬停动作。为此,您需要使用<code>ActionChains</code>:
如何使用的小示例:</p>
<pre><code>from selenium.webdriver import ActionChains
locator = driver.find_element_by_xpath("xpath where you need to move a mouse")
actions = ActionChains(driver)
actions.move_to_element(locator)
actions.click().perform()
</code></pre>
<p>单击所需的点后,按如下方式提取文本:</p>
<pre><code>currency_value = driver.find_elements_by_css_selector(".highcharts-tooltip-box.highcharts-color-0>text[data-z-index]>tspan:nth-of-type(2)").text
</code></pre>