Instapy: Looks like instagram was updated and some class tags have changed.

Created on 31 May 2018  路  36Comments  路  Source: timgrossmann/InstaPy

Expected Behavior

no error

Current Behavior

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'_t98z6')]//span"}
_nzn1h
And others. I'll do my best to document and fix

Possible Solution (optional)

new class g47SY
new likes link class zV_Nj

InstaPy configuration

bug discussion wontfix

Most helpful comment

I still have problem with: session.set_dont_unfollow_active_users.

The following error occurs: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'g47SY')]//span"}

In util.py I have already modified the:
total_posts = format_number (browser.find_element_by_xpath ("//span[contains(@class,'_t98z6')]//span").text)

To: total_posts = format_number (browser.find_element_by_xpath ("// span [contains (@ class, 'g47SY lOXF2')] // span").

but the problem continues

All 36 comments

I have the same problem. The Instagram probably changed something in the code.

i have fixed the new class https://github.com/timgrossmann/InstaPy/pull/2130 here

i don't have the new likes link class zV_Nj issue.

I still have problem with: session.set_dont_unfollow_active_users.

The following error occurs: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'g47SY')]//span"}

In util.py I have already modified the:
total_posts = format_number (browser.find_element_by_xpath ("//span[contains(@class,'_t98z6')]//span").text)

To: total_posts = format_number (browser.find_element_by_xpath ("// span [contains (@ class, 'g47SY lOXF2')] // span").

but the problem continues

@CharlesCCC the issue is in util.py, sorry for not being clear enough. And same here, @gustafsom despite changing the class to g47SY it is not fixed. 馃

yeah, still having problems even after that fix @CharlesCCC

Still the same problem:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Una
ble to locate element: {"method":"xpath","selector":"//select[@class='_fsoey']/o
ption[text()='English']"}

Same here!

First this one:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Una
ble to locate element: {"method":"xpath","selector":"//select[@Class='_fsoey']/o
ption[text()='English']"}

After setting self.switch_language = False it's gone.

And now this one:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'_t98z6')]//span"}

All since 5 hours.

Hi guys
Assuming that you are having the issue with total_posts count
Do this change in util.py file to get it work:
replace

total_posts = (browser.find_element_by_xpath(
    "//span[contains(@class,'_t98z6')]//span").text)

with

total_posts = (browser.find_elements_by_xpath(
    "//span[contains(@class,'g47SY')]")[0].text)

_I have not tested, use with care :>_

Also, the same set with different indexes returns the followers and following counts

followers_count = (browser.find_elements_by_xpath(
    "//span[contains(@class,'g47SY')]")[1].text)

and

following_count = (browser.find_elements_by_xpath(
    "//span[contains(@class,'g47SY')]")[2].text)

Thanks @jaybocc2 for amazing catch!

I believe there is also issues with

 browser.find_element_by_xpath(
         "(//div[contains(@class, '_si7dy')])[1]").click()

and others

I am having the same issue this morning. Seemed to have worked last night though.

Traceback (most recent call last):
  File "./quickstart.py", line 39, in <module>
    session.set_dont_unfollow_active_users(enabled=True, posts=15)
  File "/Users/x/InstaPy/instapy/instapy.py", line 1960, in set_dont_unfollow_active_users
    self.logger)
  File "/Users/x/InstaPy/instapy/util.py", line 103, in get_active_users
    "//span[contains(@class,'_t98z6')]//span").text)
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 293, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 752, in find_element
    'value': value})['value']
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'_t98z6')]//span"}
  (Session info: chrome=66.0.3359.181)
  (Driver info: chromedriver=2.37.544337 (x),platform=Mac OS X 10.13.4 x86_64)

@uluQulu

I made the change you mentioned above and it did resolve the initial error. The new error is:

Traceback (most recent call last):
  File "./quickstart.py", line 39, in <module>
    session.set_dont_unfollow_active_users(enabled=True, posts=15)
  File "/Users/x/InstaPy/instapy/instapy.py", line 1960, in set_dont_unfollow_active_users
    self.logger)
  File "/Users/x/InstaPy/instapy/util.py", line 116, in get_active_users
    "(//div[contains(@class, '_si7dy')])[1]").click()
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 293, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 752, in find_element
    'value': value})['value']
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"(//div[contains(@class, '_si7dy')])[1]"}
  (Session info: chrome=66.0.3359.181)
  (Driver info: chromedriver=2.37.544337 (x),platform=Mac OS X 10.13.4 x86_64)

@dbmathis
That means the code above I shared worked perfectly ;)

Cos the last output you have provided is being executed after getting total_posts count.
To make it also work, in util.py file
replace

browser.find_element_by_xpath(
    "(//div[contains(@class, '_si7dy')])[1]").click()

with

browser.find_elements_by_xpath(
    "//div[contains(@class, '_9AhH0')]")[0].click()

Everything seems to be back to working. Thanks @uluQulu and @CharlesCCC

Actually I think I spoke too soon. It has resolved those errors but now I am getting the output

INFO [2018-05-31 16:39:34] [XXX] Failed to get likers count on your post 1
ERROR [2018-05-31 16:40:50] [XXX] Unable to go to next profile post

running the command

session.unfollow_users(amount=unfollow_amount, onlyNotFollowMe = True, unfollow_after=72*60*60)

@alxhoff
Your are missing latest commits, I encourage you to pull latest files.
But also you are right about that element.
Do this to get it work, in util.py file

1.

replace

likers_count = (browser.find_element_by_xpath(
    "//a[contains(@class, '_nzn1h')]/span").text)

with

likers_count = (browser.find_element_by_xpath(
    "//a[contains(@class, 'zV_Nj')]/span").text)
2. AND

replace

browser.find_element_by_xpath(
    "//a[contains(@class, '_nzn1h')]").click()

with

browser.find_element_by_xpath(
    "//a[contains(@class, 'zV_Nj')]").click()
3. AND

replace

tmp_list = browser.find_elements_by_xpath(
    "//a[contains(@class, '_2g7d5')]")

with

tmp_list = browser.find_elements_by_xpath(
    "//a[contains(@class, 'FPmhX')]")

_there are 2 of tmp_list, replace both_

4. AND

replace

tmp_list = browser.find_elements_by_xpath(
    "//div[contains(@class, '_3gwk6')]/a")

with

tmp_list = browser.find_elements_by_xpath(
    "//div[contains(@class, '_1xe_U')]/a")
5. AND _(last step)_

replace

browser.find_element_by_xpath(
    "//a[@class='_3a693 coreSpriteRightPaginationArrow']"
    "[text()='Next']").click()

with

browser.find_element_by_xpath(
    "//a[contains(@class, 'HBoOv')]"
    "[text()='Next']").click()

All of the changes above are been done in util.py file (_just search terms to be replaced..._)

This should solve all of the problems you have and will encounter in get_active_users definition which is requested by set_dont_unfollow_active_users method.

If you pull latest files, you should apply all of the changes in this page again, cos these changes are fresh new and are not included in latest files.

Cheers xD (_BTW I have tested none of them in InstaPy, use with care :P_)

Thanks, @uluQulu and @CharlesCCC. Grateful for Instapy and the great support.

Thanks, seems to be working again, at least those errors are gone. But I am still getting

INFO [2018-05-31 18:13:55] [XXX] Post 1 | Likers: found 1003, catched 504
ERROR [2018-05-31 18:14:09] [XXX] Unable to go to next profile post
INFO [2018-05-31 18:14:36] [XXX] Failed to get likers count on your post 2
ERROR [2018-05-31 18:15:28] [XXX] Unable to go to next profile post
INFO [2018-05-31 18:15:55] [XXX] Failed to get likers count on your post 3
ERROR [2018-05-31 18:16:46] [XXX] Unable to go to next profile post
...

I have the latest commit as well.

Cheers

@alxhoff, I am seeing the same as you after pulling the latest files and making the changes above.

Hey guys @alxhoff, @dbmathis
It happened cos it couldn't move to the _Next_ post.
_And interestingly the same code worked well on Chrome console but while testing finally in InstaPy I saw the bug raised by selenium.._
Shortly, to solve it, just re-apply the 5th step with _removing_ [0]

browser.find_element_by_xpath(
    "//a[contains(@class, 'HBoOv')]"
    "[text()='Next']").click()

_there is no more [0] indexing there..._

*I've also updated that part in my comment above

Yep works. Many thanks @uluQulu

Can someone PR those changes please ? @uluQulu thank you for all the effort

Thanks @uluQulu. Working now.

not working for me 馃槄

Traceback (most recent call last):
File "quickstart.py", line 41, in
session.set_dont_unfollow_active_users(enabled=True, posts=5)
File "/Users/User/Downloads/InstaPy-master/instapy/instapy.py", line 2357, in set_dont_unfollow_active_users
self.logger)
File "/Users/User/Downloads/InstaPy-master/instapy/util.py", line 202, in get_active_users
"//span[contains(@class,'_t98z6')]//span").text)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 368, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 858, in find_element
'value': value})['value']
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'_t98z6')]//span"}
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.13.4 x86_64)

Hey @clevebounce
For my suggestions work,
you should apply all of the changes in all three posts above:
https://github.com/timgrossmann/InstaPy/issues/2131#issuecomment-393531365 (_your problem was solved in this one_), https://github.com/timgrossmann/InstaPy/issues/2131#issuecomment-393550848 and https://github.com/timgrossmann/InstaPy/issues/2131#issuecomment-393567856.

@CharlesCCC, I've got a PR on the line and my future PR will be on relationship data tools, so don't you count me xD

Also, those suggestions was a bit for quick help but for a PR they might needed more care and more approvals :>

@uluQulu

after applying #2131 #2136

Traceback (most recent call last):
File "quickstart.py", line 41, in
session.set_dont_unfollow_active_users(enabled=True, posts=5)
File "/Users/User/Downloads/InstaPy-master/instapy/instapy.py", line 2357, in set_dont_unfollow_active_users
self.logger)
File "/Users/User/Downloads/InstaPy-master/instapy/util.py", line 211, in get_active_users
"(//div[contains(@class, '_9AhH0')])[0]").click()
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 368, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 858, in find_element
'value': value})['value']
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"(//div[contains(@class, '_9AhH0')])[0]"}
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.13.4 x86_64)

Hey @clevebounce
It looks like you grabbed ready PR by @jaybocc2 at #2136 which did not apply the fix in https://github.com/timgrossmann/InstaPy/issues/2131#issuecomment-393550848 properly.

I encourage you to manually apply all of the changes in the three posts I mentioned above and I am sure @jaybocc2 will fix it in PR soon.

@uluQulu thanks for pointing out. I've updated the PR with the correct fix.

I've tested #2136 and it is working for me.

I applied the new changes with git pull but still having these error...

Traceback (most recent call last):
File "quickstart.py", line 25, in
session.login()
File "C:\Users\hp\InstaPy\instapy\instapy.py", line 322, in login
self.bypass_suspicious_attempt):
File "C:\Users\hp\InstaPy\instapy\login_util.py", line 136, in login_user
"//select[@class='_fsoey']/option[text()='English']").click()
File "C:\Users\hp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 387, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\hp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 957, in find_element
'value': value})['value']
File "C:\Users\hp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "C:\Users\hp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//select[@class='_fsoey']/option[text()='English']"}

Traceback (most recent call last):
File "quickstart.py", line 41, in
session.set_dont_unfollow_active_users(enabled=True, posts=4)
File "C:\UsersXXX\Documents\bot1\instapy\instapy.py", line 2357, in set_dont_unfollow_active_users
self.logger)
File "C:\UsersXXX\Documents\bot1\instapyutil.py", line 205, in get_active_users
if posts >= total_posts:
TypeError: '>=' not supported between instances of 'int' and 'str'

I made all the changes but giving me this error this time. When will a fixed commit will come for noobs like me

Hi guys

@nnamdei
Your issue is unrelated to the fixes in this page, check out #2133 and see if it works, if not, let us know :)

@animetrk
Your InstaPy files are old and it happened cos you did those changes without pulling latest file.
I recommend you to pull latest files and apply these easy modifications.

Hey Guys,

After pulling the latest files and applying all of uluQulu's changes I still cant get it to work. I am getting the following error:

Traceback (most recent call last): File "quickstart.py", line 41, in <module> session.set_dont_unfollow_active_users(enabled=True, posts=5) File "/root/InstaPy/instapy/instapy.py", line 2357, in set_dont_unfollow_active_users self.logger) File "/root/InstaPy/instapy/util.py", line 211, in get_active_users "//div[contains(@class, '_9AhH0')]")[0].click() TypeError: 'WebElement' object does not support indexing

@Lacroix92
_You wrote probably find_element_by_xpath instead of find_elements_by_xpath_.
Make sure you have applied all of the fixes correctly and in correct places.

Oh shame on me. You're right. I just forgot the 's' in elements. Thanks, it is working again now!

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

deronsizemore picture deronsizemore  路  3Comments

n0sw34r picture n0sw34r  路  3Comments

thisishotdog picture thisishotdog  路  3Comments

seuraltimez picture seuraltimez  路  3Comments

Naramsim picture Naramsim  路  3Comments