ChromeFindElements & ChromeGetElementData

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
shadowesq
Newbie
Posts: 10
Joined: Sat Feb 08, 2020 12:51 am

ChromeFindElements & ChromeGetElementData

Post by shadowesq » Mon Jun 29, 2020 5:18 am

I'm having some problems getting these two commands to work together. Here is the issue.
I execute the ChromeFindElements command thusly:
ChromeFindElements>session_id,xpath,/html/body/form/div[3]/div[2]/table/tbody/tr/td/div[2]/div/div[3]/table/tbody/tr/td[1]/div/div/table/tbody/tr[1]/td/table/tbody/tr/td/a,elements

When I inspect elements in the watchlist, I see that there is data there, and that the elements array has one entry.

Then, in order to properly view the contents of the elements array, I execute the ChromeGetElementData command like so:
ChromeGetElementData>session_id,elements_1,text,ElementText
ChromeGetElementData>session_id,elements_1,value,ElementValue

For good measure, I am looking at both text and values.
But the result is that ElementText is blank and ElementValue is Null

How can the ChromeFindElements command return what appear to be valid values, while the ChromeGetElementData command appears to be blissfully ignorant of any data at all?

Any help on this would be appreciated.

Photos are attached.

Respectfully,

Chris
smxpathscrren1.jpg
smxpathscrren2.jpg

shadowesq
Newbie
Posts: 10
Joined: Sat Feb 08, 2020 12:51 am

Re: ChromeFindElements & ChromeGetElementData

Post by shadowesq » Mon Jun 29, 2020 5:23 am

Here is the other photo which did not seem to load....
smxpathscrren1.jpg

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ChromeFindElements & ChromeGetElementData

Post by Marcus Tettmar » Tue Jun 30, 2020 3:44 pm

Hi,

Looks like you are querying an anchor ('a') tag?

If so there won't be a value - anchors don't have values - but would often have text. E.g. if it looks something like:

<a ...>text here</a>

But an anchor doesn't always have text - it could have an image within it instead for example. It could have some other element within it and not have any text.

There's an undocumented feature (will update docs now) that lets you specify any html attribute, so we could query the innerHTML, or even get the outerHTML:

ChromeGetElementData>session_id,elements_1,attribute/innerHTML,ElementText

Or:

ChromeGetElementData>session_id,elements_1,attribute/outerHTML,ElementText

innerHTML will get you everything that sits inside the anchor tag - it's children. outerHTML will include the html of itself. Could be useful - could then parse that to pull out what you need.

https://www.w3schools.com/jsref/prop_html_innerhtml.asp
https://www.w3schools.com/jsref/prop_html_outerhtml.asp
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

shadowesq
Newbie
Posts: 10
Joined: Sat Feb 08, 2020 12:51 am

Re: ChromeFindElements & ChromeGetElementData

Post by shadowesq » Wed Jul 01, 2020 5:09 pm

Thank you Marcus!

I will take a look to see if (1) I can get the data I need without reference to the <a> tag and (2) if those new features you mentioned will help me out.

Regards,

Chris

shadowesq
Newbie
Posts: 10
Joined: Sat Feb 08, 2020 12:51 am

Re: ChromeFindElements & ChromeGetElementData

Post by shadowesq » Thu Jul 02, 2020 3:52 pm

Dear Marcus,

Thank you! It worked!!!

I struggled with the code for another hour, because no matter what I tried, the ChromeFindElements command was not returning any values to me. But then I stumbled upon the css selector option, and I gave that a try. Sure enough, the ChromeFindElements returned a value.

And then I used this line of code.....

ChromeGetElementData>session_id,URL_Elements_1,attribute/href,URLTextInner

...and the system returned the complete URL to me... perfectly!

I went to bed after that - it was 3 AM. But I slept with a smile on my face, finally having a solution.

THANKS MARCUS!!!

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ChromeFindElements & ChromeGetElementData

Post by Marcus Tettmar » Tue Jul 07, 2020 9:18 am

Magic :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts