0

How do I use Javascript to find role = ColumnHeader below, and then the Text field underneath it (ProductNumber)?

Basically trying to collect all the grid column names into an array, for Test Automation.

enter image description here

Resource:

Javascript: Select all data-qa attributes on HTML Page

1 Answers1

0

You can use querySelectorAll,

 var colHeaders = document.querySelectorAll('[role = ColumnHeader]');

It will select all the elements in the DOM with the given selectors.

Now to get all the name of the column header, you can do the following,

var colHeaderNames = [];
document.querySelectorAll('[role = ColumnHeader] > .k-link').forEach(item => colHeadersNames.push(item.innerText));
Md Sabbir Alam
  • 4,937
  • 3
  • 15
  • 30
  • Hi Updated the answer. – Md Sabbir Alam Oct 28 '20 at 17:30
  • hi, accepted answer and gave points, maybe you can help answer this question? https://stackoverflow.com/questions/64585817/javascript-selector-find-checkbox-for-corresponding-sibling-text –  Oct 29 '20 at 14:19