Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

74
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda