Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

querySelectorAll

Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

querySelectorAll

Post by Laertes »

Hello !
Is it possible to create a variable to extract the content in this way?

document.querySelectorAll('button.pv-top-card-v2-section__link.pv-top-card-v2-section__link-experience span.pv-top-card-v2-section__entity-name')[0].innerText
"TTarga - Carreira e Recolocação"
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: querySelectorAll

Post by salvadordf »

The querySelectorAll method is supported by Chromium.
Use a JavaScript extension like the one in the JSRTTIExtension demo to get the result in Delphi.
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: querySelectorAll

Post by Laertes »

Hello!
Sorry, but I can not.
Could you write a sample application code?
Thank you!

Image
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: querySelectorAll

Post by salvadordf »

You only need to modify the TJSRTTIExtensionFrm.Chromium1ContextMenuCommand procedure.
Replace the line 226 and set testhtml with the querySelectorAll return value.
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: querySelectorAll

Post by Laertes »

Hello !
I did not make it.
Let's say I want to extract the information from this field from the site
"button.pv-top-card-v2-section__link.pv-top-card-v2-section__link-experience span.pv-top-card-v2-section__entity-name"

Should I report this field somewhere?

Image

Image


Thank you very much for your attention.
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: querySelectorAll

Post by salvadordf »

The TJSRTTIExtensionFrm.Chromium1ContextMenuCommand procedure would have this code when commandId is MINIBROWSER_CONTEXTMENU_JSVISITDOM :

Code: Select all

    MINIBROWSER_CONTEXTMENU_JSVISITDOM :
      if (browser <> nil) and (browser.MainFrame <> nil) then
        browser.MainFrame.ExecuteJavaScript(
          'var testhtml = document.querySelectorAll(' + quotedstr('button.pv-top-card-v2-section__link.pv-top-card-v2-section__link-experience span.pv-top-card-v2-section__entity-name') + ')[0].innerText;' +
          'myextension.sendresulttobrowser(testhtml, ' + quotedstr(CUSTOMNAME_MESSAGE_NAME) + ');',  // This is the call from JavaScript to the extension with DELPHI code in uTestExtension.pas
          'about:blank', 0);
Notice that I replaced this line in the original code :

Code: Select all

'var testhtml = document.body.innerHTML;' +
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: querySelectorAll

Post by Laertes »

Hello !
Thank you very much, it worked out with the right mouse button.
How could I pass the result straight to an edit?
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: querySelectorAll

Post by salvadordf »

The TJSRTTIExtensionFrm.Chromium1ProcessMessageReceived procedure saves the text in FText and sends a MINIBROWSER_SHOWTEXTVIEWER message to the form.

TJSRTTIExtensionFrm.ShowTextViewerMsg is executed when the form receives the MINIBROWSER_SHOWTEXTVIEWER message. You only need to set MyEdit.Text := FText; and remove the SimpleTextViewerFrm references from that procedure.
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: querySelectorAll

Post by Laertes »

salvadordf wrote: Wed Dec 05, 2018 8:36 pm The TJSRTTIExtensionFrm.Chromium1ProcessMessageReceived procedure saves the text in FText and sends a MINIBROWSER_SHOWTEXTVIEWER message to the form.

TJSRTTIExtensionFrm.ShowTextViewerMsg is executed when the form receives the MINIBROWSER_SHOWTEXTVIEWER message. You only need to set MyEdit.Text := FText; and remove the SimpleTextViewerFrm references from that procedure.
Butto1.onclik.....
Edit1.text:= FText;
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: querySelectorAll

Post by Laertes »

Sorry, but how do you get this result without having to right-click?
I would like to click the button and display the result in the edit. According to the image.
Image
Post Reply