硒:如何通过文本找到元素

发布于 2025-02-11 12:51:40 字数 637 浏览 1 评论 0原文

我试图用硒搜索文字搜索元素,但没有发现任何有用的东西。该元素在下面显示:

< div class =“ slick-cell l0 r0 project”>< span class =“ project-name”>< a href =“/reportss.htm#p10075”&gt ; mfit</a></span></div>

这种类型有多个元素,因此我需要通过mfit找到此元素,然后返回HREF。

我尝试使用不起作用的XPath的倍数可能性。

  • driver.find_elements(by.xpath,“ //*[contains(@*,'mfit')]]”)并浏览列表
  • driver.find_element(by.xpath,“/xpath,”/ /*[conting(@*,'mfit')]”)
  • driver.find_element(by.xpath,“ // span [@class ='project-name'''and contains(。,'mfit ')]”)

有人可以帮我吗?

I'm trying to search element by text with selenium but didn't find anything that work. The element is displayed below:

<div class="slick-cell l0 r0 project"><span class="project-name"><a href="/reports.htm#p10075">MFIT</a></span></div>

There are multiple elements of this type so I need to find this element by MFIT and return the href.

I've tried multiples possibilities using XPath which didn't work.

  • driver.find_elements(By.XPATH, "//*[contains(@*, 'MFIT')]") and go over the list
  • driver.find_element(By.XPATH, "//*[contains(@*, 'MFIT')]")
  • driver.find_element(By.XPATH, "//span[@class='project-name' and contains(., 'MFIT')]")

Can someone help me ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宣告ˉ结束 2025-02-18 12:51:40

尝试:

driver.find_element(By.XPATH, "//a[contains(text(), 'MFIT')]").get_attribute('href')


WebDriverWait(driver,20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(text(), 'MFIT')]")))

#Imports

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

Try:

driver.find_element(By.XPATH, "//a[contains(text(), 'MFIT')]").get_attribute('href')


WebDriverWait(driver,20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(text(), 'MFIT')]")))

#imports

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文