Okay, you can achieve this using the Chrome Console by combining document.querySelectorAll with a specific CSS selector and then iterating through the results to call .click().
Here are a couple of ways, with the first being the most concise if your browser supports the :has() pseudo-class (most modern browsers do):
Method 1: Using :has() (Recommended, Modern Browsers)
This method selects the button element directly if it contains the specified img tag.
Open Chrome DevTools:
Right-click anywhere on the page and select "Inspect" or "Inspect Element".
Alternatively, press F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac).
Go to the Console Tab: Click on the "Console" tab.
Paste the Code: Copy and paste the following JavaScript code into the console:
javascript
// Select buttons with the class 'expand_collapse_btn' that have the specific image inside
const buttonsToClick = document.querySelectorAll('button.expand_collapse_btn:has(img[width="16"][src="/images/expand.png"])');
// Iterate over the NodeList and click each button
buttonsToClick.forEach(button => button.click());
// Optional: Log the number of buttons found and clicked
console.log(`Clicked ${buttonsToClick.length} buttons.`);
Method 2: Selecting Buttons and Filtering (More Compatible)
This method first selects all buttons with the specified class and then uses JavaScript to check if they contain the required image.
Open Chrome DevTools (as described above).
Go to the Console Tab.
Paste the Code: Copy and paste the following JavaScript code into the console:
javascript
// 1. Select all buttons that have the class 'expand_collapse_btn'
const allButtons = document.querySelectorAll('button.expand_collapse_btn');
// 2. Filter this list to find only those containing the specific image
const targetButtons = Array.from(allButtons).filter(button => {
// Check if the button contains the specific image as a descendant
// Using querySelector here is fine as it finds the first descendant match
return button.querySelector('img[width="16"][src="/images/expand.png"]');
});
// 3. Iterate over the filtered list and click each button
targetButtons.forEach(button => button.click());
// Optional: Log the number of buttons found and clicked
console.log(`Clicked ${targetButtons.length} buttons.`);
Explanation:
document.querySelectorAll(selector): This finds all elements in the document that match the provided CSS selector and returns them as a NodeList.
'button.expand_collapse_btn': This CSS selector targets elements that are <button> tags AND have the class expand_collapse_btn.
:has(img[width="16"][src="/images/expand.png"]) (Method 1): This is a pseudo-class that checks if the preceding element (button.expand_collapse_btn) contains (as a child or descendant) an element matching the selector inside the parentheses.
img[width="16"][src="/images/expand.png"]: This selects an <img> tag that has both the width attribute set to "16" AND the src attribute set to "/images/expand.png".
Array.from(allButtons): Converts the NodeList returned by querySelectorAll into an Array, which allows us to use array methods like filter.
.filter(button => ...): Creates a new array containing only the buttons for which the inner function returns true.
button.querySelector(...): Within the filter function, this checks if the current button being processed contains the specific image as a descendant.
buttonsToClick.forEach(button => button.click()) or targetButtons.forEach(button => button.click()): This loops through the selected list of buttons and calls the .click() method on each one, simulating a user click.
Choose the method that works best for you. Method 1 is generally preferred for its conciseness if :has() is supported.