【问题标题】:MS Access VBA Selenium .getText after Submitting Form / WebPage提交表单/网页后的 MS Access VBA Selenium .getText
【发布时间】:2019-04-12 03:40:38
【问题描述】:

Access 2016,刚刚从 I.E DOM 切换到 Selenium /Chrome :) 自动提交表单/网页后需要获取 eBay 列表 ID 号 - 这部分真的很好用!使用下面的 XPath 或 Css 行获取运行时 428“对象不支持此属性或方法”。错误时的 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 被缩短了。需要数据项中的“价值”。

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

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

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

【问题讨论】:

    标签: vba selenium web-scraping ms-access-2016


    【解决方案1】:

    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
    

    【讨论】:

    • QHarr 你说得对,它是 438。在尝试解决这个问题后太接近屏幕错误......效果很好。感谢您的宝贵时间。
    猜你喜欢
    • 2014-02-14
    • 2020-06-22
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多