javascriptgoogle-photos

How to programatically select photos in a Google Photos album?


I'm trying to programatically select a photo from within a Google Photos Album in the browser, via the console.

I've tried the following:

const photo = document.getElementsByClassName('p137Zd')[0].parentElement

photo.querySelectorAll('div[role="checkbox"]').click()

But I'm getting an error. This quick code was meant to trigger a click() event and select the first photo in an album, but I'm getting an error saying:

Uncaught TypeError: photo.parentElement.querySelectorAll(...)[0].click is not a function

Can anyone help me achieve this?


Solution

  • You get a collection from querySelectorAll so this could be a dupe

    This is is simpler:

    const photo = document.querySelector('.p137Zd').parentElement
    

    In any case try

    photo.querySelectorAll('div[role="checkbox"]').forEach(div => div.click());