HTML Viewer DOM Parser / Editor

Hello,

Does anybody hav an idea on how to parse the DOM from HTML Viewer , I need to be able to hide a part of the page before displaying it to the viewer and the only way to hide is to hide a class .

I did saw that MBS has something but unfortunately they don’t have [quote]getElementsByClassName[/quote] available to I’ll have to look for other ways doing that.

Any ideas would be more than helpful.

Thanks.

Ok so apparently the [quote]ExecuteJavaScript[/quote] worked in this case but apparently I have a problem with the HTMLViewer.

The process is the following

I load the page, I fill the form , I submit the form and once the processing complete it changes the url from https://website/submit to https://website/submitted?caseid=xxxx, but in my case I cannot get the URL change anywhere in the HTML Viewer events.

Is there a way to be able to do that ? if I fill that form in a normal browser I can see the url changed but not in the HTML Viewer events. I tried in DocumentComplete, DocumentProgressChanged; StatusChanged but unfortunately nothing shows the correct URL.

Thanks.

Look in the https://documentation.xojo.com/api/deprecated/htmlviewer.html#htmlviewer-cancelLoad or possibly https://documentation.xojo.com/api/deprecated/htmlviewer.html#htmlviewer-newwindow events

Hello Michael, unfortunately it does not work , CancelLoad gets fired if the load was canceled so it’s not my case ,and NewWindow is when you want to load new window, as well not my case .

On my side the URL gets changed I guess by js or something and does not refresh the page at all so the Viewer does not know that URL was changed if no page refresh was requested , I assume, I’m not sure.

Apparently there is no other way to detect that with the current module.

thanks.

The webhtmlviewer has a hashtagchanged event which works fine for this purpose. I am in the same boat, want to use this functionality with htmviewer control for desktop but don’t know how.

StatusChanged is unwise to use except with macOS (and that may change). TitleChange should work but is limited in the number of characters you get in the event.

Well none of them are working , Status change works only if you press or hoover a url in the interface and it shows the URL but that defeats the purpose of automating things, as Joost said as well, there are things on Web that are not on desktop so I guess it would be nice to have same functionality everywhere at least on this side as after all it supposed to work that way .

@XOJO side, is it possible to have this changed ? or add the functionality by subclassing it ? and how ?

Thanks.

You are mistaken about HTMLViewer (deprecated) — Xojo documentation - it fires when the page requests to load a URL - the load is only canceled if you return True. It may not work in your particular case, depending on how the javascript/HTML is changing the page URL…

Another way would be to set up a repeating Xojo timer which uses HTMLViewer ExecuteJavascript to check the javascript variables - it’s likely that some variable on the page is changing that you could monitor to detect the change.

Is this a public website? If you give us the URL we might be able to help.

You’ll get a statuschanged or titlechanged event if, in the HTMLviewer, your javascript changes the status or the title, as in:

window.status = "some string" document.title = "some string"

Your event handler is then called with the new status/title as parameter.

[quote=465988:@Tim Streater]You’ll get a statuschanged or titlechanged event if, in the HTMLviewer, your javascript changes the status or the title, as in:

window.status = "some string" document.title = "some string"

Your event handler is then called with the new status/title as parameter.[/quote]
While I did get that part the problem is that the service is not changing the title and because it is an external service, I cannot control it , so I have to depend and adapt for it , and now having title changed is out of the question . Status changed in the same time is little bit fishy and not always firing properly I guess so I cannot rely on that.

[quote=465982:@Michael Diehr]You are mistaken about https://documentation.xojo.com/api/deprecated/htmlviewer.html#htmlviewer-cancelLoad - it fires when the page requests to load a URL - the load is only canceled if you return True. It may not work in your particular case, depending on how the javascript/HTML is changing the page URL…

Another way would be to set up a repeating Xojo timer which uses HTMLViewer ExecuteJavascript to check the javascript variables - it’s likely that some variable on the page is changing that you could monitor to detect the change.

Is this a public website? If you give us the URL we might be able to help.[/quote]
Hello Michael, well the problem is that the service is public but it requires a username and password to login and as well a certificate so unfortunately we cannot share that , I wish I could.

The service works like following ,

You have the login page which we managed to make it work, by inputing the username and password and logging in

Then you have to fill the form with the requirements you need, and once this is done it generates a document with a barcode and as well changes the url with [quote]https://website/submitted?caseid=xxxx[/quote] where xxxx could be one or multiple separated by “,” then once we get those id’s we call the api and we do the rest of the processing.

And so far we are obliged to use it that way so we cannot skip it .

Regarding the timer so far I have no idea how they doit and how they use it, I already asked the question and if I could have the exact script that is doing the update then maybe as you said I could add a trigger handler and update and get the id’s once updated , so far waiting for update from their side, but as well looking for other solutions.

Thanks

[quote=466017:@Aurelian Negrea]changes the url with
https://website/submitted?caseid=xxxx
[/quote]

Can you dig into the javascript to see exactly how they are doing this? For example, if they are calling

 // JavaScript
  window.location.href = "https://website/submitted?caseid=xxxx"

then I think (but am not 100% sure) that HTMLViewer.CancelLoad will fire.

Seems like it’d be easier to get the company to provide you with an API for this. Otherwise the next time they change their site, all of this stuff could stop working.

[quote=466428:@Michael Diehr]Can you dig into the javascript to see exactly how they are doing this? For example, if they are calling

 // JavaScript
  window.location.href = "https://website/submitted?caseid=xxxx"

then I think (but am not 100% sure) that HTMLViewer.CancelLoad will fire.[/quote]
Thanks Michael, I’ll have a look, so far waiting for their reply.

Nope, they will not change and due to the restrictions and accreditations we are obliged to use the interface. They do have an API as well but for this part we need to stick to their interface.

Thanks.

Ok so they did offered for us an option that is quite ok if we make it work, so apparently they did added an attribute that supposed to hold those id’s once generated , now because the page gets loaded via Ajax so there is no page refresh what would be the best way to trigger this and get the data ?

They have something like this :

<div class="topBottom"> resultids="4323">

and they did said that I could get it using

document.querySelector('.topBottom').GetAttribute('resultids')

Now I guess I could call a timer that will always check if there is any result for that but how do I get the result of that in the process and do the rest of the steps ?

Thanks in advance

It’s unclear to me that one can get anything back from an HTMLViewer without using the StatusChanged or TitleChanged events as I mentioned upthread.

How about this: can you make yourself an HTML page containing an