InstaPy / InstaPy

📷 Instagram Bot - Tool for automated Instagram interactions
GNU General Public License v3.0
16.73k stars 3.77k forks source link

Login XPaths are broken #6657

Open thEpisode opened 1 year ago

thEpisode commented 1 year ago

Expected Behavior

Can login and execute program

Current Behavior

Cannot login and program fails. Console logs:

InstaPy Version: 0.6.16
 ._.  ._.  ._.  ._.  ._.  ._.  ._.  ._.  ._.
Workspace in use: "C:/Users/admin/InstaPy"
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
INFO [2022-11-30 11:36:02] [tardeo.bar]  Session started!
oooooooooooooooooooooooooooooooooooooooooooooooooooooo
INFO [2022-11-30 11:36:06] [tardeo.bar]  - Cookie file not found, creating cookie...
WARNING [2022-11-30 11:36:16] [tardeo.bar]  Login A/B test detected! Trying another string...
WARNING [2022-11-30 11:36:21] [tardeo.bar]  Could not pass the login A/B test. Trying last string...
ERROR [2022-11-30 11:36:26] [tardeo.bar]  Login A/B test failed!
        b"Message: Unable to locate element: //div[text()='Log In']\nStacktrace:\nRemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8\nWebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:182:5\nNoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:394:5\nelement.find/</<@chrome://remote/content/marionette/element.sys.mjs:280:16\n"
Traceback (most recent call last):
  File "C:\Python310\lib\site-packages\instapy-0.6.16-py3.10.egg\instapy\login_util.py", line 337, in login_user
    login_elem = browser.find_element(
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 861, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //button[text()='Log In']
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:182:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:394:5
element.find/</<@chrome://remote/content/marionette/element.sys.mjs:280:16

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python310\lib\site-packages\instapy-0.6.16-py3.10.egg\instapy\login_util.py", line 343, in login_user
    login_elem = browser.find_element(
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 861, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //a[text()='Log in']
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:182:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:394:5
element.find/</<@chrome://remote/content/marionette/element.sys.mjs:280:16

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python310\lib\site-packages\instapy-0.6.16-py3.10.egg\instapy\login_util.py", line 350, in login_user
    login_elem = browser.find_element(
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 861, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //div[text()='Log In']
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:182:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:394:5
element.find/</<@chrome://remote/content/marionette/element.sys.mjs:280:16

........................................................................................................................
CRITICAL [2022-11-30 11:36:26] [tardeo.bar]  Unable to login to Instagram! You will find more information in the logs above.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

INFO [2022-11-30 11:36:29] [tardeo.bar]  Sessional Live Report:
        |> No any statistics to show

[Session lasted 35.04 seconds]
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
INFO [2022-11-30 11:36:29] [tardeo.bar]  Session ended!
ooooooooooooooooooooooooooooooooooooooooooooooooooooooo

Possible Solution (optional)

InstaPy configuration

import random
import os

from dotenv import load_dotenv
from instapy import InstaPy
from instapy.util import smart_run

load_dotenv()

# login credentials
insta_username = os.getenv('SERVICE_USERNAME')
insta_password = os.getenv('SERVICE_PASSWORD')

# restriction data
dont_like_list = os.getenv('DONT_LIKE_WORD_LIST').split(',')
ignore_user_list = os.getenv('IGNORE_USER_LIST').split(',')

# Prevent commenting on and unfollowing friend_user_list
friend_user_list = os.getenv('FRIEND_USER_LIST').split(',')

# Prevent posts that contains next words
ignore_word_list = os.getenv('IGNORE_WORD_LIST').split(',')

# Set similar accounts and influencers from your niche to target...
target_user_list = os.getenv('TARGET_USER_LIST').split(',')

# Skip all business accounts, except from list given...
target_business_categories = os.getenv(
    'TARGET_BUSINESS_CATEGORY_LIST').split(',')

# InstaPy session
session = InstaPy(username=insta_username,
                  password=insta_password,
                  headless_browser=False,
                  disable_image_load=True,
                  multi_logs=True,
                  want_check_browser=False,
                  browser_executable_path=r"C:\Program Files\Mozilla Firefox\firefox.exe")

# Main function
with smart_run(session):
    # HEY HO LETS GO
    # general settings
    session.set_dont_include(friend_user_list)
    session.set_dont_like(dont_like_list)
    session.set_ignore_if_contains(ignore_word_list)
    session.set_ignore_users(ignore_user_list)
    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=1,
                                    min_following=1,
                                    min_posts=1)

    session.set_skip_users(skip_private=True,
                           skip_no_profile_pic=True,
                           skip_business=False,
                           dont_skip_business_categories=[target_business_categories])

    session.set_user_interact(amount=3, randomize=True,
                              percentage=80, media='Photo')
    session.set_do_like(enabled=True, percentage=90)
    session.set_do_follow(enabled=True, percentage=40, times=1)

    # activities

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

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

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

    # Interact with the chosen target_user_list
    session.follow_user_followers(random_targets, amount=random.randint(
        30, 60), randomize=True, sleep_delay=600, interact=True)

    # UNFOLLOW activity
    # Unfollow nonfollowers after one day...
    session.unfollow_users(amount=random.randint(75, 100), instapy_followed_enabled=True,
                           instapy_followed_param="all", style="FIFO", unfollow_after=48*60*60, sleep_delay=600)

    # Unfollow all users followed by InstaPy after one week to keep the following-level clean...
    session.unfollow_users(amount=random.randint(75, 100), instapy_followed_enabled=True,
                           instapy_followed_param="all", style="FIFO", unfollow_after=168*60*60, sleep_delay=600)
frostynikov commented 1 year ago

Any solutions?

JudeMurphy commented 1 year ago

In your xpath_compile.py search for 'Log In' and change it to "Log in".

They changed the casing in the 'in'. Selenium is quite literal. @frostynikov @thEpisode

SebastianHagemeyer commented 1 year ago

I am also having this issue

asuliman17 commented 1 year ago

Selenium has had major updates which are causing these breaking changes. One of two things needs to be done.