fairgame icon indicating copy to clipboard operation
fairgame copied to clipboard

Crash on add to cart

Open idolize opened this issue 4 years ago • 7 comments

Describe the bug

Noticed that my instance crashed on it's own. Looks like it was trying to add an item to cart.

Running code from the development branch on commit 749c61383c6b4b47363715ba989819a8b13dc664

Here is the stacktrace:

2021-02-03 09:47:35|0.6.0.dev3|INFO|Found 3 offers in the HTML.  Comparing offers...
2021-02-03 09:47:35|0.6.0.dev3|INFO|Item in stock and in reserve range!
2021-02-03 09:47:35|0.6.0.dev3|INFO|clicking add to cart
Traceback (most recent call last):
  File "app.py", line 54, in <module>
    cli.main()
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/username/Dev/bots/fairgame1/cli/cli.py", line 71, in decorator
    func(*args, **kwargs)
  File "/Users/username/Dev/bots/fairgame1/cli/cli.py", line 245, in amazon
    amzn_obj.run(delay=delay, test=test)
  File "/Users/username/Dev/bots/fairgame1/stores/amazon.py", line 230, in run
    asin = self.run_asins(delay)
  File "/Users/username/Dev/bots/fairgame1/utils/debugger.py", line 34, in wrapper_debug
    value = func(*args, **kwargs)
  File "/Users/username/Dev/bots/fairgame1/stores/amazon.py", line 436, in run_asins
    if self.check_stock(asin, self.reserve_min[i], self.reserve_max[i]):
  File "/Users/username/Dev/bots/fairgame1/utils/debugger.py", line 34, in wrapper_debug
    value = func(*args, **kwargs)
  File "/Users/username/Dev/bots/fairgame1/stores/amazon.py", line 787, in check_stock
    in_stock = self.check_stock(
  File "/Users/username/Dev/bots/fairgame1/utils/debugger.py", line 34, in wrapper_debug
    value = func(*args, **kwargs)
  File "/Users/username/Dev/bots/fairgame1/stores/amazon.py", line 730, in check_stock
    price = parse_price(prices[idx].get_attribute("innerHTML"))
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 139, in get_attribute
    attributeValue = self.parent.execute_script(
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 634, in execute_script
    return self.execute(command, {
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/username/.local/share/virtualenvs/fairgame1-0cwWha33/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
  (Session info: chrome=88.0.4324.96)

To Reproduce Unsure of exact cause or reproduction steps at this time.

Expected behavior Continue trying and not crash.

Screenshots I believe this is what it was seeing at the time. I can provide the HTML capture too if needed.

screenshot-failed-atc_02-03-2021_09_47_30

Desktop (please complete the following information):

  • OS: macOS 10.15.7
  • Browser chrome
  • Version 88.0.4324.96

Additional context I think the 3080 was available and then quickly sold out. Maybe Amazon was in a weird transient state?

idolize avatar Feb 03 '21 21:02 idolize

Exact same problem for me.. "failed add to cart" in notifications.

LgWagon avatar Feb 07 '21 20:02 LgWagon

For me item gets added to cart but It's not detected, so it starts looping... Sidebar basket isn't loaded. And 1cm to left i have correct amount. Snimka zaslona (41)

Edit: So changing website from smile.amazon.de to amazon.de resolves issue and now does self checkout

Theunrealglitch avatar Feb 07 '21 22:02 Theunrealglitch

There seem to be two distinct issues where the DOM element is being considered stale. They are both in similar areas of the code, but I'm not exactly sure why. This ticket has an error parsing the price from an existing price node and #497 seems to be failing to interact with the previously found atc button. It's possible this is a driver issue, but that seems unlikely.

Does this happen during a test purchase? Does it seem that there is anything 'different' about the page that the ATC fails on? We can catch the stale exception, but I fear that'll just mask the issue of the page going stale for some reason. If it's unavoidable, we can trap StaleElementReferenceException, but I'd like to have a bit more insight into why we're getting these for some people.

unapproachable avatar Feb 13 '21 13:02 unapproachable

Changing website to amazon.de resolves the issue. The error appears during a test purchase on amazon.smile.de..

LgWagon avatar Feb 14 '21 07:02 LgWagon

Lines 600 - 622 the atc_buttons name is incorrect.

Use this instead:

    while True:
        atc_buttons = self.driver.find_elements_by_xpath(
               #this was incorrect
                '//*[@name="submit.add-to-cart"]'
        )
        if atc_buttons:
            # Early out if we found buttons
            break

        test = None
        try:
            test = self.driver.find_element_by_xpath(
                '//*[@id="olpOfferList"]/div/p'
            )
        except sel_exceptions.NoSuchElementException:
            pass

        if test and (test.text in NO_SELLERS):
            return False
        if time.time() > timeout:
            log.info(f"failed to load page for {asin}, going to next ASIN")
            return False

    timeout = self.get_timeout()

blnk2007 avatar Feb 14 '21 22:02 blnk2007

@blnk2007 please indicate what domain you are using or what is happening on the page. This is not applicable to everyone. image

DakkJaniels avatar Feb 14 '21 22:02 DakkJaniels

That's interesting. It was broken for me on smile.amazon.com in the chrome browser and this fixed it. I can try changing the code to look for either button.

What domain are you using?

On Sun, Feb 14, 2021, 5:57 PM DakkJaniels [email protected] wrote:

@blnk2007 https://github.com/blnk2007 please indicate what domain you are using or what is happening on the page. This is not applicable to everyone. [image: image] https://user-images.githubusercontent.com/6080734/107891645-f7e1b180-6eed-11eb-802f-955acc011aa7.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Hari-Nagarajan/fairgame/issues/487#issuecomment-778855979, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUPFV2MIE3XIJKNI3Z3U7LS7BILZANCNFSM4XBTGLGQ .

blnk2007 avatar Feb 15 '21 01:02 blnk2007