InstaPy
InstaPy copied to clipboard
Accepted IG cookies by default... problem
Expected Behavior
IG should find and click on Accept All cookie.
Current Behavior
It is xPath problem and IG could not find Accept All bottom.
Possible Solution (optional)
the xPath should change from xpath["accept_igcookie_dialogue"] = {"accept_button": "//button[text()='Accept']"} to xpath["accept_igcookie_dialogue"] = {"accept_button": "//button[text()='Accept All']"}
Hi @kharazian
I tried your solution. It also seems to get stuck at the 'Sign up to see photos and videos from your friends' Instagram app prompt. It cannot find the login button.
INFO [2021-10-30 22:17:30] [*******] Timed out with failure while explicitly waiting until visibility of element located!
InstaPy version 0.6.14
Traceback (most recent call last):
File "C:\Users\PC\Desktop\instagram_py\bot.py", line 4, in
I found a solution for both of your issues (quick & dirty fix!)
1) To get pass the cookie dialog make sure xpath search corresponds to the actual accept button in this case "Accept All" instead of "Accept".
To do this, go to the xpath_compile.py file and change the last line from
xpath["accept_igcookie_dialogue"] = {"accept_button": "//button[text()='Accept']"}
to
xpath["accept_igcookie_dialogue"] = {"accept_button": "//button[text()='Accept All']"}
2) To get pass the "Sign up to see photos and videos from your friends" page I injected some lines to click on the "Log In" button before moving on entering the credentials.
I did this right after the cookie dialog. Thus, change the "accept_igcookie_dialogue" def in the login_util.py file from
def accept_igcookie_dialogue(browser, logger):
"""Presses 'Accept' button on IG cookie dialogue"""
offer_elem_loc = read_xpath(accept_igcookie_dialogue.__name__, "accept_button")
offer_loaded = explicit_wait(
browser, "VOEL", [offer_elem_loc, "XPath"], logger, 4, False
)
if offer_loaded:
logger.info("- Accepted IG cookies by default...")
accept_elem = browser.find_element_by_xpath(offer_elem_loc)
click_element(browser, accept_elem)
to
def accept_igcookie_dialogue(browser, logger):
"""Presses 'Accept' button on IG cookie dialogue"""
offer_elem_loc = read_xpath(accept_igcookie_dialogue.__name__, "accept_button")
offer_loaded = explicit_wait(
browser, "VOEL", [offer_elem_loc, "XPath"], logger, 4, False
)
if offer_loaded:
logger.info("- Accepted IG cookies by default...")
accept_elem = browser.find_element_by_xpath(offer_elem_loc)
click_element(browser, accept_elem)
"""New Login Dialog Workaround"""
login_elem_loc = read_xpath("mobile_click_login", "login_button")
login_loaded = explicit_wait(
browser, "VOEL", [login_elem_loc, "XPath"], logger, 4, False
)
if login_loaded:
logger.info("Login loaded...")
login_elem = browser.find_element_by_xpath(login_elem_loc)
click_element(browser, login_elem)
Correspondingly we need to add the corresponding xpath in the xpath_compile.py file. Therefore, add the following line to it:
xpath["mobile_click_login"] = {"login_button": "//button[text()='Log In']"}
Let me know if this works for you!
Cheers Andreas
Hi @andrsschultz
That works!
Thanks
Nice fix ! Thanks.
Think its more time for a new update via pip
Hi,
Thanks for the fix.
However, I cannot login into Instagram after correcting both issues.
Traceback (most recent call last): File "quickstart.py", line 19, in
with smart_run(bot): File "/usr/lib/python3.8/contextlib.py", line 113, in enter return next(self.gen) File "/usr/local/lib/python3.8/dist-packages/instapy/util.py", line 1983, in smart_run session.login() File "/usr/local/lib/python3.8/dist-packages/instapy/instapy.py", line 433, in login if not login_user( File "/usr/local/lib/python3.8/dist-packages/instapy/login_util.py", line 297, in login_user accept_igcookie_dialogue(browser, logger) File "/usr/local/lib/python3.8/dist-packages/instapy/login_util.py", line 718, in accept_igcookie_dialogue login_elem = browser.find_element(login_elem_loc) File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 855, in find_element return self.execute(Command.FIND_ELEMENT, { File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 428, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidArgumentException: Message: unknown variant //button[text()='Log In']
, expected one ofcss selector
,link text
,partial link text
,tag name
,xpath
at line 1 column 37
@andrsschultz I am getting:
KeyError: 'mobile_click_login'