【问题标题】:Selenium Webdrive (VBA) - find an element's attribute, where there are duplicate attributes of the same nameSelenium Webdriver (VBA) - 查找元素的属性,其中有相同名称的重复属性
【发布时间】:2019-05-30 16:19:42
【问题描述】:

我正在尝试将属性 data-orderid 中的值“1234567!1234567”存储在我工作表中的单元格中

我在 VBA 中使用的代码是:

Cells(x,y) = d.FindElementByXPath("/html/body/table[3]/tr[@class='report']").getAttribute("data-orderid").Text

这是我试图从中获取信息的 HTML 代码示例:

<body>
<table class="report">
    <tr class="wide">...</tr>
    <tr data-orderid="1234567!1234567" data-index="1" data- 
    thumbnail="www.image.jpg">...</tr>`

预期的输出是“1234567!1234567”,但是当我尝试运行我的代码时弹出错误:NoSuchElementError, ElementNotFound

【问题讨论】:

  • 你的 xpath 正确吗?
  • 试试这个 XPath //*[contains(@data-orderid,'!')]
  • 可以分享一下网址吗?

标签: excel vba selenium xpath web-scraping


【解决方案1】:

试试下面的。 selenium v​​ba的方法是Attribute

d.findElementByCss("[data-index='1']").Attribute("data-orderid")

你最后不需要.text

【讨论】:

  • 谢谢!我把头发拉到这个上面。仅供参考,没有 .text 的那个对我有用
猜你喜欢
  • 2013-07-03
  • 1970-01-01
  • 2018-09-01
  • 1970-01-01
  • 2015-02-03
  • 1970-01-01
  • 2012-12-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多