0

Using Excel 2019 VBA, I am trying to get data from a paragraph on a web page with this structure.

<p>
    <strong>Release Date:</strong>
    " May 30th 2022"
    <br>

    <strong>From:</strong>
    <a href=URL>Title</a>
    <br>

    <strong>Performers:</strong>
    <a href=URL1>Name1</a>, 
    <a href=URL2>Name2</a>, 
    <a href=URL3>Name3</a>
</p>

This is the xpath for the paragraph.

/html/body/div[11]/div/div/div[1]/div[1]/div/div/p[1]

To get the individual elements ("Release Date", "From" and "Performers"), I am having to parse the entire paragraph with "Instr"s or regular expressions.

Is there a way to directly reference these elements with XPath?

For example, the "Release Date" Xpath is:

/html/body/div[11]/div/div/div[1]/div[1]/div/div/p[1]/text()[1]

I have tried to get this directly with the following but none of them work.

webdriver.FindElementsByXPath("//div[11]/div/div/div[1]/div[1]/div/div/p[1]/text()")(1) - Invalid Selector

webdriver.FindElementsByXPath("//div[11]/div/div/div[1]/div[1]/div/div/p[1]").Attribute("text")(1) - returns nothing

webdriver.FindElementsByXPath("//div[11]/div/div/div[1]/div[1]/div/div/p[1]")(1).Attribute("text") - returns nothing

webdriver.FindElementsByXPath("//div[11]/div/div/div[1]/div[1]/div/div/p[1]").text(1) - invalid procedure call

webdriver.FindElementsByXPath("//div[11]/div/div/div[1]/div[1]/div/div/p[1]")(1).text - returns entire paragraph

Any advice would be greatly appreciated.

braX
  • 11,506
  • 5
  • 20
  • 33
GBMedusa
  • 131
  • 4
  • 10

0 Answers0