Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
Difficulties with retrieving DOM elements

I'm trying to read an element from a dynamic website, but am facing a weird (at least to my poor understanding) issue.

Below is a snapshot from the Developer Tool from Chrome enter image description here

I'm trying to read the innertText of the highlighted line (please note this is a dynamic website, so the "li id's"change). When I'm firing document.querySelector("#\\31 60698c8-9d6c-492b-acf8-13b82467f873 > div > span.room-display-message-message") in the DevTools Console while highlighting the line as in the above snapshot the innerText is returned, but when I'm moving my selection higher up in the tree, e.g. to "iframe class = "trollbox-iframe" and then running the same script it returns "null". This behavior also pops up when making the script more random like document.querySelector("* > div > span.room-display-message-message")

Am I getting crazy or is this normal and should I take another approach?

I'm asking this because I'm developing a tool in C# using a CEFSharp Chromium webbrowser to read contents of this website, but that's not relevant at the nmoment

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

OK, itr took me a few days, but I finally got what I wanted. For those interested here's my solution:

  • First thing is to add a CefSharp.WinForms.CefSettings to your browser element, being "--disable-web-security"

  • For calling this trollbox iframe I'm using below Javascript (I know it can be simplified, but hey...it works

    var script2 = "function foo(){" + "var re = /[^-a - zA - Z!, '?\s]/g;" + "var messages = [];" + "doc = document.getElementsByClassName('trollbox-container open')[0];" + "ifrm = doc.getElementsByTagName('iframe')[0];" + "docInside = ifrm.contentDocument ? ifrm.contentDocument : ifrm.contentWindow.document;" + "docTag = docInside.getElementsByClassName('content small')[0];" + "msgList = docTag.getElementsByClassName('message-list')[0];" + "msgList_sender = msgList.getElementsByClassName('room-display-message-sender');" + "msgList_message = msgList.getElementsByClassName('room-display-message-message');" + "for (var i = 0; i < msgList_sender.length; i++)" + " {" + " var sender = msgList_sender[i].innerText;" + " var message = msgList_message[i].innerText;" + " messages.push(sender + ': ' + message);" + " }" + "return messages;" + "}" + "foo();";

Finally running this code

JavascriptResponse response = await browser1.EvaluateScriptAsync(script2);

returns me the information from the trollbox I wanted

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!