1

im working on bot Instagram like and unlike with python and selenium..

example on >> https://www.instagram.com/explore/tags/healtyfood/ > on post

i use CSS_SELLECTIOR to navigate to the like icon, then use get_attribute to get the aria-label: 'Like' or aria-label: 'Unlike'..

But the atribute didnt works..... thank for help..

this i code i've tried..

ld = driver.find_element(By.CSS_SELECTOR, '._aamw') #Span
lc = ld.get_attribute('aria-label') == 'Unlike' #Aria-label inner the span
if lc:
    print('[INFO] : Already liked this post!')
else:
    print('[INFO] : Ready to like...')
    ld.click()  
    print('[INFO] : Liking Done!')

this the ig post Code:

<span class="_aamw">
    <button class="_abl-" type="button">
            <div class="_abm0 _abm1">
                <svg aria-label="Like" class="_ab6-" color="#8e8e8e" fill="#8e8e8e" height="24" role="img" viewBox="0 0 24 24" width="24">
                    <path d=".....">
                    </path>
                </svg>
            </span>
        </div>
    </button>
</span>
  • `span` is not having `aria` attribute. `svg` element is having. So you should target `svg` element for retrieving `aria` attribute – GodWin1100 Jun 23 '22 at 11:57
  • Does this answer your question? [How to retrieve the value of the attribute aria-label from element found using xpath as per the html using Selenium](https://stackoverflow.com/questions/52009771/how-to-retrieve-the-value-of-the-attribute-aria-label-from-element-found-using-x) – GodWin1100 Jun 23 '22 at 11:59
  • @GodWin thanks... i change ti svg path then works – Bobby Wibowo Jun 24 '22 at 03:31
  • For getting attribute you need to explicitly select that element only. Not it's parent and definitely not it's child element. – GodWin1100 Jun 24 '22 at 08:50

0 Answers0