提交表单/网页后的 MS Access VBA Selenium .getText

MS Access VBA Selenium .getText after Submitting Form / WebPage

Access 2016,刚刚从 I.E DOM 切换到 Selenium /Chrome :) 需要在自动提交 Form/WebPage 后获得 eBay 上市 ID 号 - 这部分工作真的很棒!使用下面的 XPath 或 Css 行获取运行时 428 "Object doesn't support this property or method"。错误时的 getItemID 值显示为 null (getItemID = "")

    Select Case [Forms]![SettingsForm]![ListingOptionsFrame]
    Case 1
       'Listing Item --------------- AutoListOption------------------------- 
   Dim getText As String
   Me.ItemID = getItemID

   driver.FindElementByXPath("//input[@value='List item']").Click  
   PauseTimed (10)  'submitting Listing to eBay     

   getText = driver.FindElementByXPath("//*@id='Email']").getAttribute("data-itemid") '.getText() in place of .getAttribute 428's 
  'getText = driver.FindElementByCss("#Email").getAttribute("data-itemid") '.getText() in place of .getAttribute 428's as well 
Case 2      

ebay 的 HTML - 为简洁起见缩短。需要来自 data-itemid 的 "value"。

   <a id="Email" ...... data-itemid="143211121121"></a>  

如有必要,也可以从 中获取 "value"。我也有类似的 428 错误,需要使用 Right() 来获取 "value".

一个想法? 428 错误可能来自页面重新加载或提交后的弹出窗口吗?页面地址不变。如果您能指出我的方向,将不胜感激?

vba selenium 中的方法很简单 Attribute() 并且您现有的错误代码应该是 438。

driver.FindElementByXPath("//*@id='Email']").Attribute("data-itemid")

您正在使用一个 webElement,对于 VBA 实现,它具有不同的语法。在 IE 中通过 Microsoft Internet Controls 使用节点时,您使用 getAttribute 语法,它与 Element 接口的 javascript 方法的命名相同。


Option Explicit

Public Sub Example()
    Dim d As WebDriver
    Const URL As String = "https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors"

    Set d = New ChromeDriver

    With d
        .Start "Chrome"
        .get URL

        Debug.Print .FindElementByCss("#edit-history-menu").Attribute("type")

        .Quit
    End With
End Sub