Instapy: Invalid Like Element

Created on 22 Jul 2020  路  39Comments  路  Source: timgrossmann/InstaPy


Expected Behavior

ability to like the targeted element defined on the code

Current Behavior

this element doesn't exist anymore, so the script is not able to find it

Possible Solution (optional)

Update the code with the new element definition :
xpath["like_image"] = {
"like": "//section/span/button/div[[local-name()='svg']/@aria-label='Like']",
"unlike": "//section/span/button/div[[local-name()='svg']/@aria-label='Unlike']",
}

InstaPy configuration

Modify the definition of the Like element

wontfix

Most helpful comment

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

Instagram just did a change again to the html (couple of minutes ago). The same way you can change to the following lines in xpath_compile.py file:

xpath["like_image"] = {
    "like": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Unlike']",
}

Actually Instagram added one more html element 'span' after the last 'div'. Try to replace with the code above, it worked for me. Hopefully it'd work for you too :)

All 39 comments

Here some details of a possible resolution from @Lisiadito :

xpath["like_image"] = {
"like": "//section/span/button/div[[local-name()='svg']/@aria-label='Like']",
"unlike": "//section/span/button/div[
[local-name()='svg']/@aria-label='Unlike']",
}

It just need to be updated into the code directly

from today same issue for me
try solution from Mohanbarman in "pull request" but nothing

from today same issue for me
try solution from Mohanbarman in "pull request" but nothing

any update?

from today same issue for me
try solution from Mohanbarman in "pull request" but nothing

any update?

No.....
I try Many Version of xpath and i try to modify myself the xpath but nothing
Waiting for help....

Same issue here!

same issue here as well.

Any update about the problem??

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

I just tried this, and it worked well. Thanks!

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

Worked for me too ! Thank you @Lisiadito

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

Still dosen't work for me, just me?

@bronzeboy what version of InstaPy do you have installed?

Tomorrow try to reset my raspberry and reinstall all...
I hope is only a corrupt python library

@bronzeboy what version of InstaPy do you have installed?

The last one 0.6.9 and I manually upgraded browser.py and xpath from github latest commit

@bronzeboy not sure what you updated in the browser.py but with a clean 0.6.9 install and then modifying the xpath_compile.py with the changes i suggested it should work.

@bronzeboy not sure what you updated in the browser.py but with a clean 0.6.9 install and then modifying the xpath_compile.py with the changes i suggested it should work.

Hi!, I did this exactly this and did not work for me. All im using is the feature like by tag on my code... idk still get the invalid like element

@angelonso I've encountered this problem too.I "was" using python 3.7 in Spyder and Mozilla Firefox (the latest version, I think it's 0.78),Windows 10 64bit. I tried changing the xpath_compile.py 'like-image' codepiece but still gave 1.Invalid like element, and 2. Wrong pathway error.

Tried the solutions here, no avail ,so I went to my other device(same python version) but I had Mozilla developer. It works without changing any code(still puzzled why).

If that doesn't work then implement the suggested code above to a lower version of Mozilla or firebug.

@english-coconut Thank you very much for yoy reply! I finally managed to make it work. For me it world using the developer browser and changing the code. Also no idea why but thank you 馃憤:D

Tomorrow try to reset my raspberry and reinstall all...
I hope is only a corrupt python library

did u manage to solve it on raspberry?

@bronzeboy not sure what you updated in the browser.py but with a clean 0.6.9 install and then modifying the xpath_compile.py with the changes i suggested it should work.

It was an error by my part, sorry and thanks!

Tomorrow try to reset my raspberry and reinstall all...
I hope is only a corrupt python library

did u manage to solve it on raspberry?

This morning I reset my raspberry .....
try on "rpi3 b+" and "rpi2 b"
And than:

INSTALL OS

For work:
xvfb-run python3 yourscript.py

Everything work without any modification
In the last build is already modified browser.py (hide selenium extension) and xpath_compile.py

Cron is ok with xvfb

I think my old problem was with some python library but i'm unable to remove old library from os

Many than to everyone and may thanks to @Lisiadito

Tomorrow try to reset my raspberry and reinstall all...
I hope is only a corrupt python library

did u manage to solve it on raspberry?

This morning I reset my raspberry .....
try on "rpi3 b+" and "rpi2 b"
And than:

INSTALL OS

For work:
xvfb-run python3 yourscript.py

Everything work without any modification
In the last build is already modified browser.py (hide selenium extension) and xpath_compile.py

Cron is ok with xvfb

I think my old problem was with some python library but i'm unable to remove old library from os

Many than to everyone and may thanks to @Lisiadito

thanks , i'm now able to run it.

Sometimes just with some random instagram errors "Instagram error: The link you followed may be broken, or the page may have been removed..."

trying to figure it out what can be

That happens when a user changes the username. So it's normal and doesn't crash the Skript since it is expected.

That happens when a user changes the username. So it's normal and doesn't crash the Skript since it is expected.

thanks didn't knew that. btw, do you know any way to avoid the block on likes?

What are your settings for likes? Obviously there is some kind of limit per hour which is enforced by Instagram. But sometimes the script can verify if the like went through due to a timeout or something and then you get the occasional message that you might be blocked from liking.

session.set_user_interact(amount=2, randomize=True, percentage=60)
session.set_do_follow(enabled=True, percentage=40)
session.set_do_like(enabled=True, percentage=80)

# activity
session.like_by_tags(random.sample(like_tag_list, 3),
                     amount=random.randint(50, 100), interact=True)

I have it like this. It might be that, because when I got that block message at the script i'm still able to put likes on the app and at the browser

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

Instagram just did a change again to the html (couple of minutes ago). The same way you can change to the following lines in xpath_compile.py file:

xpath["like_image"] = {
    "like": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Unlike']",
}

Actually Instagram added one more html element 'span' after the last 'div'. Try to replace with the code above, it worked for me. Hopefully it'd work for you too :)

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

Instagram just did a change again to the html (couple of minutes ago). The same way you can change to the following lines in xpath_compile.py file:

xpath["like_image"] = {
    "like": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Unlike']",
}

Actually Instagram added one more html element 'span' after the last 'div'. Try to replace with the code above, it worked for me. Hopefully it'd work for you too :)

I'm still getting the Invalid Like Element! Error after using that code above, not sure why. I'm using a Mac and I have version 0.6.9, using FireFox to run the script using Selenium. Any Ideas?

@alfanme 's solution is working for me, for now

Should we add try block to the xpath with several possible options?

@alfanme work perfect....
Many Thanks

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

Instagram just did a change again to the html (couple of minutes ago). The same way you can change to the following lines in xpath_compile.py file:

xpath["like_image"] = {
    "like": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Unlike']",
}

Actually Instagram added one more html element 'span' after the last 'div'. Try to replace with the code above, it worked for me. Hopefully it'd work for you too :)

This one work for me too! Thanks

Could someone share how you find these paths? i tried with some extentions and use it in the code, it does'nt worked for me !
However Thank You @alfanme for the update! :heart_eyes:

Could someone share how you find these paths? i tried with some extentions and use it in the code, it does'nt worked for me !
However Thank You @alfanme for the update! 馃槏

Glad I can help you all guys.

Regarding @Aashiq-Otp request,

Here's the way how you check the path of like and unlike button.

  1. Open any post on Instagram on your browser
  2. Make sure you open the post page in the full page, not a modal/pop-up page (if you open the post in pop-up mode. Hit the refresh/reload button on the browser)
  3. Go to inspect element, if you familiar with inspect element, there's a button with cursor and box around it, I use firefox so it's on the top left corner of the inspect element window. Click the icon, and hover onto the post's like button.
  4. There you can see the html structure hierarchy of the button. The very top left tag is the parent, and more tags go along to the bottom right (indentation).
  5. In this case, just ignore the outer
    tag. Start from the
    one (the child of outer div). Match the path with the html hierarchy from section tag all the way before the tag. In the previous case, I found out that IG added one more tag before the tag which is the like icon.

By the way, I made the steps in picture so you can get the visual --> How to check like/unlike button path

Hopefully this could help you all to solve this problem in the future 馃憣馃徏

how do we change the lines in the xpath file?

there is a open PR which should fix this problem. for now you can change these lines in the file xpath_compile.py

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}

Instagram just did a change again to the html (couple of minutes ago). The same way you can change to the following lines in xpath_compile.py file:

xpath["like_image"] = {
    "like": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Unlike']",
}

Actually Instagram added one more html element 'span' after the last 'div'. Try to replace with the code above, it worked for me. Hopefully it'd work for you too :)

I dont know why.. but this dont work for me...
I checked the HTML, and "span" was added, but despite editing and updating Instapy, it continues to give "Invalid like element".

Just updated to the newest version and it seems to work fine now.

I updated yesterday, and it worked.
But today I try to start the script, and again "Invalid Like Element".
I checked the html of the instagram page, everything is right... idk what is the problem!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

46960 picture 46960  路  3Comments

neomh picture neomh  路  3Comments

harrypython picture harrypython  路  3Comments

rahulkapoor90 picture rahulkapoor90  路  3Comments

CodeMaster1 picture CodeMaster1  路  3Comments