Can we access elements by css path in VBA?

I'm automating couple of websites through vba and accessing elements by classname, tagname, id, name or sometimes combination of these..

Do we have any option to select elements on HTML document by their css path?

I was searching this on google but didn't find my answer..

xTremeExcel

Answers


If you have html like this:

<html>
<head>
</head>
<body>
    <h1 class="a">Heading a</h1>
    <h1 class="b">Heading b</h1>
</body>
</html>

Then you can do something like this in VBA

Dim xmlDoc As DOMDocument60
Set xmlDoc = New DOMDocument60
xmlDoc.Load ("c:\htmltest.htm")

Debug.Print xmlDoc.SelectNodes("//h1").Length
Debug.Print xmlDoc.SelectNodes("//h1[@class='a']").Length

to identify your nodes. The "length" is just for demo purpose. You must make a reference to Microsoft XML 6.0 for this to work.


You can do this with jQuery

http://api.jquery.com/category/selectors/

also a useful article on CSS selectors

http://www.w3.org/TR/css3-selectors/


Need Your Help

Outlook Add-In tutorial?

c# visual-studio outlook-addin

Does anyone know of a good example for getting started with Outlook add-ins using C#?

iCalendar reader for Python?

python icalendar

I'm looking to automate the status reports that I have to send to my manager. Since I use a to-do software that writes to iCalendar format, I would like be able to format an email out of the ics fi...