0

Actually I am trying to make an instabot using Selenium in PyCharm and trying to hit like button, but I am unable to trigger that like button due to it's svg property, if anyone know how to click on that like button please help me out.

Here's the code:

def findhashtag(self):
    self.driver.get('https://www.instagram.com/explore/tags/'+self.hashtag+'/')
    like_picture = self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div')
    like_picture.click() #this is to open picture
    elememnt = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(("xpath", '//*[local-name()="svg"][@class="_8-yf5"]')))
    #self.driver.find_element_by_xpath('//button[@class="wp06b"]//*[name()="svg"]').click() #another method to click on that
    #self.driver.find_element_by_xpath('//*[name()="svg"]//*[name()="viewBox" and @class="_8-yf5")').click() #another method to click on that
    #self.driver.find_element_by_link_text("Like").click() #another method to click on that
    follow = WebDriverWait(self.driver, 15).until(lambda d: d.find_element_by_xpath('//button[text()="Follow"]'))
    follow.click() #this is to follow and its working fine
    try:
        like_button = WebDriverWait(self.driver, 15).until(lambda d: d.find_element_by_xpath('//button[@class="wp06b"]//*[name()="svg"]'))
        like_button.click() #trying to clic[enter image description here][1]k on like button
    except:
        print("not liked")
1
  • Does this help. SVG elements don't have an onclick method but you can work around that, at leat in javascript. Commented Feb 2, 2020 at 8:17

1 Answer 1

0

Maybe if you change 'find element by XPath' to Element to be clickable.

    from selenium.webdriver.support import expected_conditions as EC  

    try:
        WebDriverWait(self.driver, 15).until(EC.element_to_be_clickable((By.XPATH, '#XPATH here'))).click()
    except:
        print('this did not work')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.