InstaPy icon indicating copy to clipboard operation
InstaPy copied to clipboard

Problem with XPath

Open brocool opened this issue 7 years ago • 9 comments

Expected Behavior

to login successfully

Current Behavior

Traceback (most recent call last): File "quickstart.py", line 27, in with smart_run(session): File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 112, in enter return next(self.gen) File "C:\Users\user\Desktop\InstaPy-master\instapy\util.py", line 1676, in smart_run session.login() File "C:\Users\user\Desktop\InstaPy-master\instapy\instapy.py", line 378, in login self.bypass_with_mobile): File "C:\Users\user\Desktop\InstaPy-master\instapy\login_util.py", line 262, in login_user "//button[text()='Log in']") File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value'] File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\user\AppData\Local\Programs\Python\Python37\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":"//button[text()='Log in']"} (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)

Possible Solution (optional)

InstaPy configuration

settings import os import time from tempfile import gettempdir

from selenium.common.exceptions import NoSuchElementException

from instapy import InstaPy

insta_username = '' insta_password = ''

set headless_browser=True if you want to run InstaPy on a server

set these in instapy/settings.py if you're locating the ibrary in the /usr/lib/pythonX.X/ directory: Settings.database_location = '/path/to/instapy.db' Settings.chromedriver_location = '/path/to/chromedriver'

session = InstaPy(username=insta_username, password=insta_password, headless_browser=True, multi_logs=True)

try: session.login()

session.set_relationship_bounds(enabled=False,
			 potency_ratio=-1.21,
			  delimit_by_numbers=True,
			   max_followers=4590,
			    max_following=5555,
			     min_followers=45,
			      min_following=77)
session.set_blacklist(enabled=True, campaign='camp1')
session.set_dont_like(['beauty', 'forex', 'shop', 'store'])
session.set_ignore_if_contains(['follow', 'follower', 'gain', '.id', '_id', 'forex', 'binary', 'meme', 'promotion'])
session.set_do_follow(enabled=True, percentage=100, times=1)
session.set_do_comment(enabled=True, percentage=100)
session.set_comments(['amazing', 'nice'])

for cycle in range(99999):
    print("\n\nLOOP {}\n".format(cycle+1))
    session.like_by_tags(['natgeo', 'adventure'], amount=1)

except Exception as exc: if changes to IG layout, upload the file to help us locate the change if isinstance(exc, NoSuchElementException): file_path = os.path.join(gettempdir(), '{}.html'.format(time.strftime('%Y%m%d-%H%M%s',))) with open(file_path, 'wb') as fp: fp.write(session.browser.page_source.encode('utf8')) print('{0}\nIf raising an issue, please also upload the file located at:\n{1}\n{0}'.format( '*' * 70, file_path)) full stacktrace when raising Github issue raise

finally: end the bot session session.end()

brocool avatar Feb 21 '19 00:02 brocool

and please @timgrossmann get back the old version of instapy. it was easier. now it just became harder

brocool avatar Feb 21 '19 00:02 brocool

hi

you can change login_util.py

login_button = browser.find_element_by_xpath(
    "//button[text()='Log in']")

to

login_button = browser.find_element_by_xpath(
    "//button//div[text()='Log in']")

SeoMinbong avatar Feb 21 '19 01:02 SeoMinbong

You can join Discord for more communication.

SeoMinbong avatar Feb 21 '19 01:02 SeoMinbong

If You want find me name BongGun

SeoMinbong avatar Feb 21 '19 01:02 SeoMinbong

Fix PR is waiting for merge https://github.com/timgrossmann/InstaPy/pull/4035

CharlesCCC avatar Feb 21 '19 01:02 CharlesCCC

@seominbong I don't know if you're god send but OMG it worked thank you so much! I wanna hug you!!!!!!!

brocool avatar Feb 21 '19 01:02 brocool

@charlesccc the way @seominbong did it worked. Thank you so much

brocool avatar Feb 21 '19 01:02 brocool

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 same error

GeoffreyPG avatar May 03 '19 20:05 GeoffreyPG

I'm getting a similar error:

Cookie file not found, creating cookie... Login A/B test detected! Trying another string...

The login_button no longer exists in login_util.py and has been replaced with

login_elem = browser.find_element_by_xpath(
    read_xpath(login_user.__name__, "login_elem")
)

Any help here?

Julio-Maldonado avatar Aug 18 '19 22:08 Julio-Maldonado