python-3.x - Python Selenium 如何检索当前的 xpath
问题描述
目前致力于网络任务自动化。
当我访问我想要的网页时,我让 Selenium 使用他们的 Xpath 查找元素
receivedTime = browser.find_elements_by_xpath('//*[starts-with(@id, "anchor") and contains(@id, "_0")]')
for time in receivedTime:
所以它找到了所有这些元素。在 for 循环期间,我将如何检索当前正在使用的 xpath?这样我就可以使用基于当前 xpath 的 If 语句。
例如,如果当前 xpath == "anchor0_0":
谢谢你。
解决方案
您可以检查@id
每个元素,如下所示:
receivedTime = browser.find_elements_by_xpath('//*[starts-with(@id, "anchor") and contains(@id, "_0")]')
for time in receivedTime:
if time.get_attribute('id') == 'anchor0_0':
# Do something
推荐阅读
- android - 如何使用 SimpleExoPlayerView 从视频中获取音轨
- angular - 如何将 CCAvenue 与 .Net Core API 和 Angular 5 应用程序集成?
- android - GBoard 键盘 GIF 贴纸集成
- android - 在intellij idea中查找类的导入包
- c# - 如何在 C# 中将 PDF 转换为图像?
- python - python mpi 密钥错误“duplicate_keysharedFilename[0]”
- python - 输出信息到模板(从下一个数组)
- java - JavaFx tableview 和 tablecolumn 中的两个不同的类
- xamarin.forms - EF Database.EnsureDeleted() 和 Database.EnsureCreated() 方法上的 System.Reflection.TargetParameterCountException
- asp.net-core - 如何验证嵌入 OKTA 的 PowerBI