Reputation: 39
Im creating an Instagram bot in Selenium basically to like certain comments with other Instagram accounts, but Im unable to .click() on the xpath of Instagram's heart in the comment section of a certain comment. I really just need the correct xpath of the heart in Instagram's comment section, and I'll be done with this.
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import urllib
Link = 'https://www.instagram.com/p/CCZDF7YH5Yb/c/17958711199328488/'
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.instagram.com/')
driver.implicitly_wait(10)
driver.find_element_by_name('username').send_keys('username') #Changed for the purpose of making this thread
driver.find_element_by_name('password').send_keys('password')
Login = "//button[@type='submit']"
driver.find_element_by_xpath(Login).submit()
sleep(1)
#Logs into Instagram
print ('Logged In')
NotNow = "//button[contains(text(),'Not Now')]"
driver.find_element_by_xpath(NotNow).click()
#Clicks Pop Up
print ('Close Pop Up')
#ISSUE is Below
#CommentHeart = '//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button/svg' #THIS XPATH doesn't work?
driver.get(Link)
wait = WebDriverWait(driver, 20)
element = wait.until(EC.element_to_be_clickable((By.XPATH, '/main/div/div[1]/article/div[3]/div[1]/ul/div[2]/ul/div/li/div/span/div/button/svg'))) #THIS XPATH doesn't work
element.click()
#driver.find_element_by_xpath(CommentHeart).click()
print ('Likes Comment')```
This is the xpath I've been using, that doesn't work.
```//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/div[1]/ul/div[2]/ul/div/li/div/span/div/button/svg```
Upvotes: 2
Views: 1526
Reputation: 114
I used the xpath below to find the like button and it works for me
driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[1]/article/div[2]/section[1]/'
'span[1]/button').click()
from what I can see in your code is that you have
/section[1]/span[1]/button/svg
but it should be just
/section[1]/span[1]/button
since you want to click on the button and not svg
Upvotes: 2