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..
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
also a useful article on CSS selectors