Search code examples
vbaseleniumweb-scrapingms-access-2016

MS Access VBA Selenium .getText after Submitting Form / WebPage


Access 2016, just switched from I.E DOM to Selenium /Chrome : ) Need to get eBay listing ID Number after auto submitting Form/WebPage -this part works really sweet! Getting runtime 428 "Object doesn't support this property or method" with either XPath or Css lines below. The getItemID value on error shows as a 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's HTML -shortened for brevity. Need the "value" from data-itemid.

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

Can also get the "value" from a < span> if necessary. I had similar 428 errors as well and would need to use a Right() to get the "value".

A thought? Could the 428 error's be coming from the page reload or a popup after submitting? The page's address doesn't change. If you could point me in a direction it would be much appreciated?


Solution

  • The method in vba selenium is simply Attribute() and your existing error code should have been 438.

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

    You are working with a webElement which, for VBA implementation, has different syntax. When working with a node in IE, via Microsoft Internet Controls, you use the getAttribute syntax, which is the same naming as the javascript method of the Element interface.


    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