Chrome Driver - Traverse Iframes & Insert HTML

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

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

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Marcus Tettmar » Tue Mar 10, 2020 6:06 pm

1. This code will not replace the ENTIRE HTML. It will only replace the innerHTML of the BODY. document.body is the body tag.

2. Javascript needs quotes to be escaped. Because of the way you are extracting the body I expect the JS is erroring because there are unescaped quotes. E.g. " needs to be come \"
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
Grovkillen
Automation Wizard
Posts: 498
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Grovkillen » Mon Mar 23, 2020 12:53 pm

Marcus Tettmar wrote:
Tue Mar 03, 2020 10:40 am
Again, if this is something people find useful we can turn this into a native function.
Ah, I would very much like that.
Let>ME=%Script%

Running: 15.0.9
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 697
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Dorian (MJT support) » Mon Mar 23, 2020 1:11 pm

Marcus Tettmar wrote:
Tue Mar 03, 2020 8:59 pm
Well, since we were working on this anyway and it was further ahead than I thought, I managed to reprioritise a few things and get an update pushed out today with added native ChromeSwitchFrame and EdgeSwitchFrame functions. Version 15.0.07. Available in the usual places.
Grovkillen wrote:
Mon Mar 23, 2020 12:53 pm
Marcus Tettmar wrote:
Tue Mar 03, 2020 10:40 am
Again, if this is something people find useful we can turn this into a native function.
Ah, I would very much like that.
It's already there, Grovkillen, see above.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Grovkillen
Automation Wizard
Posts: 498
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Grovkillen » Mon Mar 23, 2020 1:13 pm

I thought I was referring to the "ExecuteJS". Instead of having a custom sub routine it would be ideal to have it taken care of with a command.
Let>ME=%Script%

Running: 15.0.9
version history

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

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Marcus Tettmar » Mon Mar 23, 2020 1:42 pm

Code: Select all

Still struggling with this...
CODE: SELECT ALL
GoSub>ExecuteJS,session_id,document.body.innerHTML=\"<p>blah blah</p>\"
Works almost as expected, although instead of replacing the entire page, it actually just replaces everything inside the page body tag.
Correct. document.body.innerHTML = "set the html inside the BODY tag which belongs to the DOCUMENT".

This does not "replace entire document".

You could try setting document.innerHTML which I believe is a new HTML 5 feature supported by SOME browsers. I haven't tried it. It may not work. Give it a go. Another possibility is document.write(newDocument). Again I haven't yet tried it. Give it a go.

Also see:
https://stackoverflow.com/questions/675 ... e-document

But the long and short of it is that you have some javascript code which sets the inner html of the BODY element and seem surprised that only the BODY element is being updated. But that's what the code does.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
Grovkillen
Automation Wizard
Posts: 498
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Grovkillen » Mon Mar 23, 2020 6:54 pm

I would love to have a execute JavaScript command. Together with a " to /" flag. It could then be used almost like the vbscript and python implementation is working now.
Let>ME=%Script%

Running: 15.0.9
version history

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

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Marcus Tettmar » Mon Mar 23, 2020 7:11 pm

Grovkillen wrote:
Mon Mar 23, 2020 6:54 pm
I would love to have a execute JavaScript command. Together with a " to /" flag. It could then be used almost like the vbscript and python implementation is working now.
Not sure I follow. Can you explain?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
Grovkillen
Automation Wizard
Posts: 498
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Grovkillen » Mon Mar 23, 2020 8:54 pm

The ExecuteJS sub routine in your code example work just great. But couldn't that be made into a command?

ChromeExecuteJS>sessionID,JSCode

Instead of:

Code: Select all

Let>CHROMEDRIVER_EXE=C:\Program Files (x86)\Macro Scheduler 15\chromedriver.exe

ChromeStart>strSessionID
ChromeNavigate>strSessionID,url,https://www.google.com/
ChromeFindElements>strSessionID,css selector,body,strElementID
GoSub>ExecuteJS,strSessionID,document.body.innerHTML=\"THIS SHOULD BE REPLACING THE BODY INNER HTML?\";


SRT>ExecuteJS
  Let>HTTP_POSTJSON=1
  Let>body= { "script": "%ExecuteJS_Var_2%", "args": [] }
  Let>CHROMEDRIVER_PORT=9515
  HTTPRequest>http://localhost:%CHROMEDRIVER_PORT%/session/%ExecuteJS_Var_1%/execute,,POST,body,theResult
END>ExecuteJS
And what I meant by having a flag for the " is that it would be great to not have to care about adding the \ in front of the " before passing the code to the command.
Let>ME=%Script%

Running: 15.0.9
version history

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

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Marcus Tettmar » Mon Mar 23, 2020 8:58 pm

Yes. It’s on the list already. The more these new functions get used the more ideas/requests/use cases emerge.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
Grovkillen
Automation Wizard
Posts: 498
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Chrome Driver - Traverse Iframes & Insert HTML

Post by Grovkillen » Tue Mar 24, 2020 12:27 am

Marcus Tettmar wrote:
Mon Mar 23, 2020 8:58 pm
Yes. It’s on the list already. The more these new functions get used the more ideas/requests/use cases emerge.
Ah, great!
Let>ME=%Script%

Running: 15.0.9
version history

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