For this example we will use full name, I have tried getting it like this but it is not working. I have also tried the other class names in the above picture with no success.
Now that we have solved the issue I would like to know the reasoning behind not being able to do it with the simpler run javascript action, for learnings sake.
A lot of JavaScript objects are returned as arrays, and you have to properly reference the items you need.
You can use the AppleScript or pull the JavaScript statements out of it for KM actions.
------------------------------------------------------------------------------
set topCard to doJavaScriptInSafari("document.getElementById('top-card').innerHTML")
set theName to doJavaScriptInSafari("document.getElementsByClassName('fn')[0].textContent")
set theTitle to doJavaScriptInSafari("document.getElementsByClassName('title')[0].textContent")
set theLocality to doJavaScriptInSafari("document.getElementsByClassName('locality')[0].textContent")
set theIndustry to doJavaScriptInSafari("document.getElementsByClassName('industry')[0].textContent")
------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on doJavaScriptInSafari(javascriptStr)
try
tell application "Safari" to do JavaScript javascriptStr in front document
on error e
error "Error in handler doJavaScriptInSafari() of library NLb!" & return & return & e
end try
end doJavaScriptInSafari
------------------------------------------------------------------------------