miércoles, 22 de febrero de 2023

Marcar checkbox: tots i algun d'específic

 A la consola del DevTools, marcarem tots els checkbox de la pàgina web oberta entrant:


document.querySelectorAll('input[type="checkbox"]').forEach(function(checkbox) {

  checkbox.checked = true;

});

si el que volem és seleccionar els checkbox que són dins d'un xpath concret, obtenim l'xpath a partir de l'eina Selector

//*[@id="form_llistar"]/table/tbody/tr[1]/td[1]/table/tbody/tr[6]


... i a partir de l'xpath anterior entrem a la consola:

document.querySelectorAll('#form_llistar table tbody tr:nth-child(6) input[type="checkbox"]').forEach(function(checkbox) {

  checkbox.checked = true;

});

En el cas que vulguem marcar amb dos condicions, que estigui en tr(5) 

#form_llistar table tbody tr:nth-child(6) td:nth-child(4) input[type="checkbox"] + td:nth-child(5):not(:empty):first-child:not(:last-child):not([colspan])


miércoles, 8 de febrero de 2023

Chropath and Xpath

 The syntax to get only div you are interested in


//*[@id="__next"]/div[1]/div/main/div[1]/div/div/div/div[position()>=12 and position()<=22]/div


To get the list of text, we will inspect the first element, a new DevTools Window will appear. We put on il just previous to the selected div and Expand recursively

Then, in Console window, the write

console.log($0.textContent)