How to have KM choose from a browser pop-up, and then click the Apply button

On my WooCommerce Orders page, there's a pop-up entitled "Bulk Actions." (At least to me as a human being, it's a pop-up. Dunno if it's a JavaScript initiator thingy or what, and I tried using the Web Inspector from the Developer menu, but it's honestly way above my head.) I used KM's Set field to //SELECT[@id="bulk-action-selector-top"] → various options to test it, but when I try the macro, the pop-up menu ends up blank, not selecting any of the (correctly typed) options. So question #1 is how to do that correctly. (I know it's operating on the right pop-up menu, because it actually does something to the menu, but it doesn't do anything useable.)

Next, I want KM to click the Apply button (in the screenshot). How do I accomplish that?

Thanks ahead of time to anyone for responding.

Edly
Screen Shot 2022-01-13 at 6.58.21 PM

edly,

The KM action is the following

The code is the following :

function clickAction(actionName) {
    const tSelAction = document.getElementById("bulk-action-selector-top"); // set selectId

    if (tSelAction) {

        const selOption = [...tSelAction.options].find(f => f.label === actionName);

        if (selOption) {
            tSelAction.value = selOption.value;

            document.getElementById("appyButtonId").click();  // set buttonId
        }
    }
}

clickAction("Bulk actions choice");  // Fill in the select choice text

you might want to test the above code in web browser developer console first.

2 Likes

Thanks so much, macdevign_mac. I don't know the first thing about Javascript, so I wasn't sure where to fill in the select choice text. So I tried it in two different places, and I'm afraid neither worked.

I first tried (just including the last line, since if I understand correctly, I wasn't supposed to mess with anything else):
clickAction("Move to Trash"); // Fill in the select choice text

… and then tried:
clickAction("Bulk actions choice"); Move to Trash // Fill in the select choice text

Again, neither did anything. Any other suggestions?

Also, when I do get the "Bulk actions" popup to select the "Move to Trash" option, how do I then get KM to click the "Apply" button?

Thanks so much,

Edly

Sorry, just to be clearer, I meant to say that I only included the last line HERE in my forum question (just to keep it short). Of course, I pasted the whole thing you sent into the KM Execute JavaScript window.

edly,
you need to screenshot the developer console where the Select tag element is been inspected like the following

This is the minimum you need to do for us to fill in the necessary info in the code to avoid time spending on trial and error.

Okay. Well, I honestly don't even know how to do that, so have asked a web-savvier friend for help with that. Once he identifies the three elements (Select All Orders checkbox, Bulk Actions→Move to Trash, Apply), I will come back to ask how to get KM to do those things.