Search code examples
vbaseleniumxpathcss-selectorslabel

VBA Selenium Scraping text from label


How do I extract the following "label" using the chrome driver in Selenium for VBA? The information that I want is "Character 3"

HTML:

<label for="frmentermemorableinformation1:strEnterMemorableInformation_memInfo1">Character 3 &nbsp;</label>

Solution

  • To print the text Character 3 you can use either of the following locator strategies:

    • Using css_selector:

      Debug.Print .FindElementByCss("label[for^='frmentermemorableinformation1'][for$='strEnterMemorableInformation_memInfo1']").Text
      
    • Using xpath:

      Debug.Print .FindElementByXPath("//label[starts-with(@for, 'frmentermemorableinformation1') and contains(@for, 'strEnterMemorableInformation_memInfo1')]").Text