Instapy: Unable to locate element: {"method":"xpath","selector":"//body/div[3]/div/div[2]"}

Created on 3 May 2019  路  21Comments  路  Source: timgrossmann/InstaPy

Hello,
I try to change : Edit unfollow_util.py (line 809)
https://github.com/timgrossmann/InstaPy/blob/master/instapy/unfollow_util.py#L809

Old
dialog_address = "//body/div[3]/div/div[2]"

New
dialog_address = "//body/div[@ROLE="presentation"]/div/div[2]"

But i have always the same error

Expected Behavior

Current Behavior

Traceback (most recent call last):
File "quickstart.py", line 160, in
schedule.run_pending()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schedule/__init__.py", line 563, in run_pending
default_scheduler.run_pending()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schedule/__init__.py", line 94, in run_pending
self._run_job(job)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schedule/__init__.py", line 147, in _run_job
ret = job.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schedule/__init__.py", line 466, in run
ret = self.job_func()
File "quickstart.py", line 136, in job
interact=True)
File "/Users/geoffrey-poilly/Documents/Instapy/InstaPy-master/instapy/instapy.py", line 3134, in follow_user_followers
self.logfolder)
File "/Users/geoffrey-poilly/Documents/Instapy/InstaPy-master/instapy/unfollow_util.py", line 1082, in get_given_user_followers
logger, logfolder)
File "/Users/geoffrey-poilly/Documents/Instapy/InstaPy-master/instapy/unfollow_util.py", line 810, in get_users_through_dialog
dialog = browser.find_element_by_xpath(dialog_address)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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":"//body/div[3]/div/div[2]"}
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.13.6 x86_64)

Possible Solution (optional)

InstaPy configuration

"""
This template is written by @Nuzzo235

What does this quickstart script aim to do?

  • This script is targeting followers of similar accounts and influencers.
  • This is my starting point for a conservative approach: Interact with the
    audience of influencers in your niche with the help of 'Target-Lists' and
    'randomization'.

NOTES:

  • For the ease of use most of the relevant data is retrieved in the upper part.
    """

import random
from instapy import InstaPy
from instapy import smart_run
import schedule
import time

login credentials

insta_username = ''
insta_password = ''

restriction data

dont_likes = ['#exactmatch', '[startswith', ']endswith', 'broadmatch']
ignore_users = ['user1', 'user2', 'user3']

""" Prevent commenting on and unfollowing your good friends (the images will
still be liked)...
"""
friends = ['friend1', 'friend2', 'friend3']

""" Prevent posts that contain...
"""
ignore_list = ['click', 'bio', 'link', 'webcam', 'came', 'gain', 'snapchat', 'followers', 'kik']

TARGET data

""" Set similar accounts and influencers from your niche to target...
"""
targets = ['theo_diot', 'etienne_in_paris', 'benstories_', 'thoms_garcia', 'ndymorel', 'claudelhy', 'david__mrt', 'akdpn', 'legarconparisien', 'mathias.dsw', 'erwix_jvn', 'hugotruchonbartes', 'thibault_odiot', 'floriansilnicki', 'romainjl', 'eric.malheiro']

COMMENT data

comments = [
u'What an amazing shot! :heart_eyes: What do '
u'you think of my recent shot?',
u'What an amazing shot! :heart_eyes: I think '
u'you might also like mine. :wink:',
u'Wonderful!! :heart_eyes: Would be awesome if '
u'you would checkout my photos as well!',
u'Wonderful!! :heart_eyes: I would be honored '
u'if you would checkout my images and tell me '
u'what you think. :wink:',
u'This is awesome!! :heart_eyes: Any feedback '
u'for my photos? :wink:',
u'This is awesome!! :heart_eyes: maybe you '
u'like my photos, too? :wink:',
u'I really like the way you captured this. I '
u'bet you like my photos, too :wink:',
u'I really like the way you captured this. If '
u'you have time, check out my photos, too. I '
u'bet you will like them. :wink:',
u'Great capture!! :smiley: Any feedback for my '
u'recent shot? :wink:',
u'Great capture!! :smiley: :thumbsup: What do '
u'you think of my recent photo?']

get a session!

def job():
session = InstaPy(username='',
password='',
headless_browser=True,
disable_image_load=True,
multi_logs=True)

# let's go! :>
with smart_run(session):
    # HEY HO LETS GO
    # general settings
    session.set_dont_include(friends)
    session.set_dont_like(dont_likes)
    session.set_ignore_if_contains(ignore_list)
    session.set_ignore_users(ignore_users)
    session.set_simulation(enabled=True)
    session.set_relationship_bounds(enabled=True,
                                    potency_ratio=None,
                                    delimit_by_numbers=True,
                                    max_followers=7500,
                                    max_following=3000,
                                    min_followers=25,
                                    min_following=25,
                                    min_posts=3)

    session.set_skip_users(skip_private=True,
                           skip_no_profile_pic=True,
                           skip_business=True,
                           skip_business_categories=['Advertising Agency', 'Advertising/Marketing', 'Auto Dealers', 'Business & Utility Services', 'Clothing Store', 'Community Organization', 'Company', 'Consulting Agency', 'Content & Apps', 'Home Goods Stores', 'Home Services', 'Jewelry/Watches', 'Local Business', 'Local Events', 'Management Service', 'Media/News Company', 'Non-Profits & Religious Organizations', 'Party Entertainment Service', 'Personal Goods & General Merchandise Stores', 'Product/Service', 'Professional Service', 'Professional Sports Team', 'Restaurants', 'Ski Resort', 'Sport', 'Sports & Recreation', 'Transportation & Accomodation Services', 'Travel Agency', 'Wine/Spirits'])

    session.set_user_interact(amount=2, randomize=True, percentage=80,
                              media='Photo')
    session.set_do_like(enabled=True, percentage=90)
    session.set_do_comment(enabled=True, percentage=20)
    session.set_comments(comments, media='Photo')
    session.set_do_follow(enabled=True, percentage=40, times=1)
    session.set_dont_unfollow_active_users(enabled=True, posts=3)
    session.set_quota_supervisor(enabled=True,
                             sleep_after=["likes", "comments", "follows", "unfollows", "server_calls_d"],
                             sleepyhead=False,
                             stochastic_flow=True,
                             notify_me=True,
                             peak_likes=(50, 700),
                             peak_comments=(20, 250),
                             peak_follows=(30, 400),
                             peak_unfollows=(30, 400),
                             peak_server_calls=(None, 6500))

    # activities

    # FOLLOW+INTERACTION on TARGETED accounts
    """ Select users form a list of a predefined targets...
    """
    number = random.randint(3, 5)
    random_targets = targets

    if len(targets) <= number:
        random_targets = targets

    else:
        random_targets = random.sample(targets, number)

    """ Interact with the chosen targets...
    """
    session.follow_user_followers(random_targets,
                                  amount=random.randint(90, 110),
                                  randomize=True, sleep_delay=600,
                                  interact=True)

    # UNFOLLOW activity
    """ Unfollow nonfollowers after one day...
    """

    session.unfollow_users(amount=random.randint(50, 70),
                           nonFollowers=True,
                           style="RANDOM",
                           unfollow_after=24 * 60 * 60, sleep_delay=600)

"""
Have fun while optimizing for your purposes, Nuzzo
"""

schedule.every().day.at("12:29").do(job)
schedule.every().day.at("15:26").do(job)
schedule.every().day.at("18:27").do(job)
schedule.every().day.at("21:56").do(job)
schedule.every().day.at("03:34").do(job)
schedule.every().day.at("06:32").do(job)
schedule.every().day.at("09:28").do(job)

while True:
schedule.run_pending()
time.sleep(10)

wontfix

Most helpful comment

Update: change line 809 to this and it should work

dialog_address = "//div[@role='dialog']/div[2]"

All 21 comments

INFO [2019-05-03 22:33:14] [geoffrey_pg] Encountered an error to find pre in page! ~grabbed 0 usernames
b'Message: no such element: Unable to locate element: {"method":"tag name","selector":"pre"}\n (Session info: headless chrome=74.0.3729.131)\n (Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.13.6 x86_64)\n'
INFO [2019-05-03 22:33:14] [geoffrey_pg] Retrieving live Following data of geoffrey_pg at "full" range
INFO [2019-05-03 22:33:44] [geoffrey_pg] Encountered an error to find pre in page! ~grabbed 0 usernames
b'Message: no such element: Unable to locate element: {"method":"tag name","selector":"pre"}\n (Session info: headless chrome=74.0.3729.131)\n (Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.13.6 x86_64)\n

Yup, Instagram changed something, I think.

b'Message: no such element: Unable to locate element: {"method":"tag name","selector":"pre"}\n (Session info: headless chrome=74.0.3729.131)\n (Driver info: chromedriver=2.44.609545 (c2f88692e98ce7233d2df7c724465ecacfe74df5),platform=Mac OS X 10.14.4 x86_64)\n'

Mine worked well a week ago, but got same error recently.

Edit unfollow_util.py (line 809)
https://github.com/timgrossmann/InstaPy/blob/master/instapy/unfollow_util.py#L809

Old
dialog_address = "//body/div[3]/div/div[2]"

I changed it to
dialog_address = "//body/div[2]/div/div[2]"

seems it worked!

@rickycm that didn't work either

Same issue, tried modified that and still have the same issue. I believe it's the same issue ...

Traceback (most recent call last):
File "quickstart.py", line 91, in
session.like_by_tags(my_hashtags, amount=60, media=None)
File "/home/pi/.local/lib/python3.5/site-packages/instapy/instapy.py", line 1832, in like_by_tags
self.logfolder)
File "/home/pi/.local/lib/python3.5/site-packages/instapy/comment_util.py", line 78, in comment_image
comment_input[0].send_keys('\b')
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
(Session info: headless chrome=72.0.3626.121)
(Driver info: chromedriver=2.36 (a81166ad79e68fbfe7cf5ba243192d6412e26b37),platform=Linux 4.14.98-v7+ armv7l)

Update: change line 809 to this and it should work

dialog_address = "//div[@role='dialog']/div[2]"

Update: change line 809 to this and it should work

dialog_address = "//div[@role='dialog']/div[2]"

Tried this but got "stale element reference: element is not attached to the page document"

Yes i thin i have the same error:

Traceback (most recent call last):
File "schedulescript.py", line 168, in
schedule.run_pending()
File "/usr/local/lib/python3.6/dist-packages/schedule/__init__.py", line 563, in run_pending
default_scheduler.run_pending()
File "/usr/local/lib/python3.6/dist-packages/schedule/__init__.py", line 94, in run_pending
self._run_job(job)
File "/usr/local/lib/python3.6/dist-packages/schedule/__init__.py", line 147, in _run_job
ret = job.run()
File "/usr/local/lib/python3.6/dist-packages/schedule/__init__.py", line 466, in run
ret = self.job_func()
File "schedulescript.py", line 112, in follow
session.like_by_tags(random.sample(like_tag_list, 3), amount=random.randint(5, 15), interact=True)
File "/root/InstaPy/instapy/instapy.py", line 1751, in like_by_tags
self.logger)
File "/root/InstaPy/instapy/like_util.py", line 509, in check_link
web_address_navigator(browser, post_link)
File "/root/InstaPy/instapy/util.py", line 1049, in web_address_navigator
browser.get(link)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
(Session info: headless chrome=73.0.3683.75)
(Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.15.0-45-generic x86_64)

@booksix & @sebo313 your errors are different than the one posted originally by @GeoffreyPG

I was running into the same error as @GeoffreyPG so the fix I posted above has been working for me for 12+hrs now

@booksix & @sebo313 your errors are different than the one posted originally by @GeoffreyPG

I was running into the same error as @GeoffreyPG so the fix I posted above has been working for me for 12+hrs now

Nope, my error was exactly the same as @GeoffreyPG until I tried the 'fix' above, which is when the error diverged and gave me the "not attached" error. So no, my initial error was not different... only different after this 'fix' failed.

@booksix I see what mean, then the fix didn't for Mac apparently, I was on Win. I'll try to reproduce on a Mac and see

@lohriialo gotcha, yeah, that could be it. I'm going to troubleshoot some more tomorrow!

Update: change line 809 to this and it should work

dialog_address = "//div[@role='dialog']/div[2]"

this works.

Just an update from my end (and possibly the Mac side)... this fix works IF you run Firefox, instead of Chrome!

Just an update from my end (and possibly the Mac side)... this fix works IF you run Firefox, instead of Chrome!

It works well with firefox.
I found that if this fix works with chrome, it would grab for example 30 followers, but interact with some follower all the time.

Update: change line 809 to this and it should work

dialog_address = "//div[@role='dialog']/div[2]"

This works for me too. Solved the error for both follow_user_followers and interact_user_followers. Thanks!

how it works for raspi?

i am very new to this,
would you guys be so kind to explain me how i can locate the unfollow instapy util file?
so that i may try to edit the line?
i am using a mac

I got the same error. I will replace with:
dialog_address = "//div[@role='dialog']/div[2]"
and I'll post an update.

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

rahulkapoor90 picture rahulkapoor90  路  3Comments

CharlesCCC picture CharlesCCC  路  3Comments

ediooo picture ediooo  路  3Comments

ghost picture ghost  路  3Comments

seuraltimez picture seuraltimez  路  3Comments