Skip to content
Advertisement

Selenium Instagram Bot – Clicking the “Like” Button

I have written a program to go on the Instagram explore page, and like the first six photos.

Right now, I am using this rather convoluted method to find the “Like” button.

I would much rather have it formatted like I did the “click the login button” section.

So far, I have tried inspecting various elements, but I cannot pinpoint the correct one to make it uniquely select the “Like” button. Also, I could just need to use an attribute that I am unfamiliar with to uniquely select the like button.

I am super new to the python and also the selenium, so any help is appreciated.

#like
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button').click()
        sleep(3)

#Click login button
        self.driver.find_element_by_xpath('//button[@type = "submit"]').click()
        sleep(3)

Advertisement

Answer

to click on like, that web element is in svg tag, so try the below locator :

//button[@type='button']//*[name()='svg' and @aria-label='Like' and @height='24']

something like :

sleep(3)
self.driver.find_element_by_xpath("//button[@type='button']//*[name()='svg' and @aria-label='Like' and @height='24']").click()

Also, I am not sure what do you mean by

#Click login button
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement