1

Using JavaScript, how can I get the string inside of this HTML element, with the id being recItemString_GPLA\|input? Inside the element there is a string with "qty" (without quotes) that I'm trying to capture. When I inspect the element I get:

<input data-oj-internal="" type="text" readonly="" placeholder="" class="oj-inputtext-input oj- 
component-initnode" id="recItemString_GPLA|input"> == $0.

Above that element in DevTools there is:

<oj-input-text :id="[[fieldId()]]" validators="[[validators]]" on-value- 
changed="[[valueChanged.bind($data)]]" on-valid-changed="[[validChanged]]" 
value="{{value}}" required="[[required]]" readonly="[[readOnly]]" messages- 
custom="[[messagesComputed]]" display-options="[[displayOptions]]" help=" 
[[help]]" id="recItemString_GPLA" class="oj-inputtext oj-form-control oj- 
component oj-read-only oj-complete"><input data-oj-internal="" type="text" 
readonly="" placeholder="" class="oj-inputtext-input oj-component-initnode" 
id="recItemString_GPLA|input"></oj-input-text>

I have not been able to gather the string inside the element to display it to the console.

Using the pluggin SelectorGadget the element XPath is: //*[(@id = "recItemString_GPLA\|input")]

When I try and query oj-input-text directly to the console the console returns [Object NodeList]

Here is a screenshot of the inspected element: screen2

11
  • <input> elements don't have string inside of them (text content), you're probably looking to get a text node that is after this <input>, try: document.querySelector('#recItemString_GPLA\\|input').nextSibling.textContent Commented Nov 5, 2019 at 18:03
  • 1
    document.getElementById('recItemString_GPLA|input').value Commented Nov 5, 2019 at 18:03
  • Titus, I tried console.log("The next try is: " + document.querySelector('#recItemString_GPLA\\|input').nextSibling.textContent); and the console response I get is: Uncaught TypeError: Cannot read property 'textContent' of null at pullCellValue (<anonymous>:45:102) Commented Nov 5, 2019 at 18:07
  • @AdamH I tried console.log("The value of the input is: " + document.getElementById('recItemString_GPLA|input').value); and the console response I get is: The value of the input is: Commented Nov 5, 2019 at 18:11
  • I guess there is no Node after the <input/>, you should edit your question to add more context (more of the HTML) and specify exactly what you're trying to retrieve. Commented Nov 5, 2019 at 18:29

2 Answers 2

1

With jQuery you can escape special characters like this:

$('#recItemsString\\_GPLA\\|input');
Sign up to request clarification or add additional context in comments.

1 Comment

Can you elaborate on how this would help me?
1

I am really not sure which text is supposed to be produced. In the following snippet I added an input value to be displayed.

const qs=s=>document.querySelector(s);

console.log(qs('#recItemString\\_GPLA\\|input').value)
<oj-input-text :id="[[fieldId()]]" 
  validators="[[validators]]" 
  on-value-changed="[[valueChanged.bind($data)]]"
  on-valid-changed="[[validChanged]]" 
  value="{{value}}" 
  required="[[required]]"
  readonly="[[readOnly]]"
  messages-custom="[[messagesComputed]]"
  display-options="[[displayOptions]]"
  help="[[help]]" 
  id="recItemString_GPLA" 
  class="oj-inputtext oj-form-control oj-component oj-read-only oj-complete">

 <input data-oj-internal="" 
  type="text" value="some text inside ..."
  readonly=""
  placeholder=""
  class="oj-inputtext-input oj-component-initnode" 
  id="recItemString_GPLA|input">
  
</oj-input-text>

2 Comments

I've added a screenshot to show the string of the element that I inspected.
Also, keep in mind that -> value="some text inside ..." does not show when I inspect the element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.