How to simulate 'copy element' in Chrome Developer Tools with Selenium VBA

Viewed 21

I'am currently using Selenium Chrome Driver with VBA, and I want to simulate what happens when I right-click an element and then click 'Copy Element' in Chrome Developer Tools. (Refer to the screenshot below)

enter image description here

When I run a code like the below one, What I get in variable 'Resultstring' is "Keyboard shortcuts - Chrome Developers".

Private Selenium As New ChromeDriver
Dim Resultstring as String
.......
Resultstring = Selenium.FindElementByCss(".LC20lb.MBeuO.DKV0Md").Text

But that's not what I want. What I want to do is to copy

<h3 class="LC20lb MBeuO DKV0Md">Keyboard shortcuts - Chrome Developers</h3>

, which I can do with 'Copy Element' in Chrome Developer Tools.

In other words, is there any method through which I can directly access to the html script displayed in 'element' panel of Chrome Developer Tools?

Thank you in advance.

1 Answers

I solved this issue by myself!

I found that 'outerHTML' could be a keyword to get what I wanted.

Instead of

Resultstring = Selenium.FindElementByCss(".LC20lb.MBeuO.DKV0Md").Text

I tried

Resultstring = Selenium.FindElementByCss(".LC20lb.MBeuO.DKV0Md").attribute("outerHTML")

and got I wanted.

Related