Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QtWebkit how to access dynamic HTML/DOM elements after executing javascript
Forum Update on Tuesday, May 27th 2025

QtWebkit how to access dynamic HTML/DOM elements after executing javascript

Scheduled Pinned Locked Moved Qt WebKit
3 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrUser
    wrote on 3 Jul 2014, 10:33 last edited by
    #1

    I am modifying the domtraversal example. I traverse the DOM of a webpage using QWebFrame and QWebElements. When I find a certain button, I

    @.evaluateJavaScript("this.click()");@

    that element and the dynamic content loads on the page. However, the DOM that I'm traversing is still the old one from the original load, before I clicked. How do I update the QWebPage document without reloading the page? If I do

    @webView->reload();@

    the information I selected is no longer there and this starts an infinite loop of choosing the information and then reloading. I just want to refresh the DOM. I also tried reading the webView->page()->mainFrame()->documentElement() again, but it's still the same DOM.

    I'd appreciate any hints or help someone can give.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      ThatDude
      wrote on 3 Jul 2014, 14:25 last edited by
      #2

      Please provide more information...

      Does button.click() change i.e. adds/removes elements or it changes properties of existing elements?

      If it creates new content i.e. new web elements you should try to find these web elements starting from webView->page()->mainFrame()->documentElement() again
      because your QWebElement is probably holding the old web element

      NB! QWebElement could hold even removed web element for a while because you might paste it later

      If javascript executed on click() only changes attributes/values of existing web elements well then perhaps it (new content) is accessible only from javascript - I've seen that quite too often, not sure about WebKit
      e.g. IMG src="" that was changed from javasript to IMG src="someimg.jpg"
      and then 'someimg.jpg' is "visible" only from javascript
      i.e. in this case you have to use evaluateJavaScript again to get actual value of src attribute 'someimg.jpg'

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MrUser
        wrote on 4 Jul 2014, 09:41 last edited by
        #3

        Thanks for the reply ThatDude.

        Does button.click() change i.e. adds/removes elements or it changes properties of existing elements?

        It adds elements to a static table element. It doesn't change the properties (that I'm aware of), but appends to it.

        you should try to find these web elements starting from webView->page()->mainFrame()->documentElement() again

        I tried doing that. During debugging I saw that the javascript is not evaluated immediately upon returning to the main loop. Instead, the slot corresponding to the signal I emitted is called immediately and the javascript is not called until sendpostedevents() is reached in the stack. I ended up finding a workaround by not calling the javascript and loading the html I found in the jQuery arguments, but I'm still curious as to how I COULD have reloaded the DOM. It seems that just doing the same

        @QWebFrame *frame = webView->page()->mainFrame();
        QWebElement document = frame->documentElement();@

        after the javascript call might work, but I think I would have to add a slot for some signal that told me that the javascript result had been returned. Otherwise the DOM is reloaded before the javascript is even executed.

        1 Reply Last reply
        0

        1/3

        3 Jul 2014, 10:33

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved