2

I need some guidance with scraping text from a website in Chrome (v 75.0.3770.142) using Selenium Basic ChromeDriver (v 75.0.3770.140) in Excel (2013) VBE.

Here is the HTML:

<div ng-if="!ShippingDetails.isShippingCreatedOutsideSH" ng-bind="ShippingDetails.code" class="">3333333</div>

The portion I need to extract is the "3333333"

I'm still brand new to Selenium Type Library and have clumsily tried with this novice attempt so far:

Dim SHN As String
SHN = obj.FindElementByXPath("//div[@ng-if='!ShippingDetails.isShippingCreatedOutsideSH']/ng-bind[@'ShippingDetails.code']").Text
MsgBox SHN
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
DWP
  • 105
  • 1
  • 11

2 Answers2

2

To print the text 3333333 you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    • Using .Text:

      Debug.Print .FindElementByCss("div[ng-if$='isShippingCreatedOutsideSH'][ng-bind^='ShippingDetails']").Text
      
    • Using .Attribute("innerHTML"):

      Debug.Print .FindElementByCss("div[ng-if$='isShippingCreatedOutsideSH'][ng-bind^='ShippingDetails']").Attribute("innerHTML") 
      
  • Using XPATH:

    • Using .Text:

      Debug.Print .FindElementByXPath("//div[contains(@ng-if, 'isShippingCreatedOutsideSH') and starts-with(@ng-bind, 'ShippingDetails')]").Text
      
    • Using .Attribute("innerHTML"):

      Debug.Print .FindElementByXPath("//div[contains(@ng-if, 'isShippingCreatedOutsideSH') and starts-with(@ng-bind, 'ShippingDetails')]").Attribute("innerHTML") 
      

You can find a relevant discussion in Vba selenium code to get data from Li class

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

Try this

Debug.Print .FindElementByXPath("//div[@ng-bind='ShippingDetails.code']").Text
YasserKhalil
  • 9,138
  • 7
  • 36
  • 95