I am creating a bot to unfollow people on Instagram.
It was working fine but as I used it I got an error.
When I go in the page of the user that i want to unfollow i got this error:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:
This error is thrown because my selenium can not find the button unfollow the user.
My code:
try:
self._make_driver_wait("/html/body/div[1]/section/main/div/header/section/div[1]/div[2]/div/span/span[1]/button")
self.driver.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/div[1]/div[2]/div/span/span[1]/button").click()
self._make_driver_wait("//button[contains(text(), 'unfollow')]")
self.driver.find_element_by_xpath("//button[contains(text(),'unfollow')]").click()
except :
print("time out")
I don't know why it can't find the element after a period of time.
I did inspect the button and the XPath of the page was the same as in my code when I click it I could unfollow.
Does Instagram have some sort of protection? Am I doing something wrong?