0

I have an website with an ajax form, and i want to get the inner text of a specific element inside that form.

The element doesn't exist when the page is first loaded.

I'm building a chrome extension to get that innertext value and print it to the console.

As i'm very new to JS, i just made the following code:

document.addEventListener('click', function () {
    let text = document.querySelector("#\\39 8");

    if (text !== null) {
        console.log(text.innerText)
    } else {
        console.log('Nothing')
    }
})

So i'm randomly clicking the webpage getting "Nothing"s, and expecting that when the element gets loaded i'll eventually get the innerText.

Problem is, as soon as i make the login into the webpage, i have nothing on the console. No "Nothing"s, no innerText..

My manifest includes all urls

{
    "name":"Teste",
    "version": "1.0",
    "description": "Testing",
    "manifest_version": 2,
    "permissions":["storage"],
    "content_scripts": [
        {
            "matches": ["<all_urls>"],
            "js": ["background.js"]
        }]
}

Question is, what am i doing wrong? Shouldn't be expectable to have the innerText of that element being printed to the console?

EDIT:

<html xmlns="http://www.w3.org/1999/xhtml" lang="fr"><head></head>
<frameset rows="82,*,0,0" framespacing="0" frameborder="0" id="FS"></frameset>
<frame name="Display" scrolling="no" piweb_src="action=../screen/display.html"></frame>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<body class="screenDisplay"></body>
<iframe name="MrcSessionA" id="MrcSessionA" frameborder="0" scrolling="no" style="display: inline;"></iframe>
#document
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<frameset id="Working" cols="*,800" border="2" bordercolor="#CCCCCC" framespacing="2" style="width: auto;"></frameset>
<frameset rows="70,*" framespacing="0" frameborder="0" style="width: auto;">
<frame name="EmulatorScreenMrcSessionA" id="EmulatorScreenMrcSessionA" scrolling="no" piweb_src="action=../applications/as400/emulator/help.html?IdentTab=MrcSessionA">
<html>
<body id="EmulatorBody">
<div id="DivBody" style="height: 488px;">
<form action="" name="PiTnForm" id="PiTnForm" method="post" onsubmit="return false;" autocomplete="off"></form>
<table id="emulatorTable" class="Ps80" style="border-collapse: separate;"></table>
<tbody id="AllPsRows">
<tr onclick="SelectOptionLine('')">
<td colspan = "17">
<input type="text" name="NewV" id="602" onfocus="GeneFocusOn(this);setCharShiftFocus({target:this});" onblur="GeneFocusOff(this)" onmouseup="GeneGetCPInputKey(this, event,true)" onkeyup="GenePsAutoTab(this,'17',event);setCharShiftFocus({target:this});" style="color:black; " maxlength="17" fa="U  u     " colour="G u  " autotab="true" class="">

This is the tree of elements that i have. I'm trying to access the last row, the input textbox.

Ricardo Vilaça
  • 846
  • 1
  • 7
  • 18
  • 2
    Can you add the site's relevant html? – Max Mar 06 '20 at 10:30
  • Unfortunately no, it is my company's website - you would need a vpn to access it. – Ricardo Vilaça Mar 06 '20 at 10:36
  • What is the element that you're trying to select? We don't need to see the entire page/html, but we do need to see what you're trying to select. – goto Mar 06 '20 at 10:50
  • @goto1 Sure! I tried my best to copy the whole tree scheme without copying the whole page.. Not sure if there's a good way to do it. Anything i can do to help just tell me – Ricardo Vilaça Mar 06 '20 at 11:20
  • You have incorrectly copy-pasted your html code here. – Devang Mar 06 '20 at 11:28
  • Hi @Devang, i'm using "Copy OuterHTML" but i only get the line for the element that i'm selecting. How should i proceed to copy the relevant html? ( I mean, without copying the whole page) – Ricardo Vilaça Mar 06 '20 at 11:37
  • If you have correctly copy then HTML elements should be nested correctly. But in this case, it's not correct. 'Copy OuterHTML' is correct way to copy element. ' – Devang Mar 06 '20 at 11:45
  • I would suggest you to try by creating small fiddle first then implement into your code. – Devang Mar 06 '20 at 11:47
  • Yeah.. Copy OuterHTML only gives me: "" – Ricardo Vilaça Mar 06 '20 at 11:59
  • What do you mean by fiddle? – Ricardo Vilaça Mar 06 '20 at 11:59
  • I think there is an issue in your selector, that's why we need to see the html. If I'm not mistaken, your selector `#\\39 8` will match the HTML element with the tag `<8>` in an element with the id `\39`. Does this exist on the page? – Max Mar 07 '20 at 12:33

0 Answers0