Hari-Nagarajan / fairgame

Tool to help us buy hard to find items.
GNU General Public License v3.0
2.44k stars 805 forks source link

"You have no items in cart." when screenshot clearly shows item in cart #798

Open sircambridge opened 3 years ago

sircambridge commented 3 years ago

This only ever happened once, so i cant reproduce it, but fairgame managed to add an item to the cart, and got to the cart page, and the "Proceed to Checkout"(PTC) button is available, but somehow the "You have no items in cart. Going back to stock check."

see this screenshot that was taken.

notice the filename is "screenshot-no-items_05-28-2021_15_27_08"

image

what this tells me is somehow self.get_cart_count() == 0, even though clearly an item is in the cart.

its possible the state of the cart icon on the top right shows 0, even though the item is in the cart. is there a reason for this sanity check? its possible if we detect the PTC(Proceed to checkout) button, we should try and click it regardless of what self.get_cart_count() returns?

specifically this check : https://github.com/Hari-Nagarajan/fairgame/blob/master/stores/amazon.py#L1123

DakkJaniels commented 3 years ago

It checks for the button first, so if it found that first, it would have clicked it. If it doesn't find it, it checks if the cart has nothing in it. Why is the screenshot cut off? What does the cart look like in the banner at the top?image

sircambridge commented 3 years ago

oops, I was looking at a different section of the code, deep within navigate_pages(), where the self.get_cart_count() happens before a PTC button check. I stand corrected, I dont think this is what is happening, the actual logic is in handle_cart()

this is the part that confused me: image

good eye, the screenshot is cut off because thats how big the chrome window happened to be when the screenshot was taken, so in reality I have no idea what the cart icon number shows. I have since made the window bigger. @DakkJaniels do you think its possible the client side js on the amazon page simply doesnt update the dom element for the cart to 1 if its not visible? is the cart number loaded asynchronously?

is it possible there is a rare asynchronous condition where self.get_amazon_element(key="PTC") is not found, and self.get_cart_count() == 0 and the page fully loads right before the screenshot is taken? like here between lines 1420 and 1421. maybe i just had really bad luck and got caught in that tiny millisecond window where the dom was not fully loaded?

image

sircambridge commented 3 years ago

closing this issue, i cannot reproduce this.

I have since successfully clicked the Proceed to Checkout button many times without this error.

I think this issue still exists, but there is only a very tiny window of race condition where this can happen.

sircambridge commented 3 years ago

guys im reopening this because it happened again.

screenshot no-items and an item is in the cart. this time I was able to capture the fact that the cart number on the top right is indeed == 0.

image

this happens very rarely, I would say I was able to add to cart maybe 50 or 60 times before this happened once. there must be some kind of async page loading race condition where the number is 0 for a split second.

I think we should continue checking for the PTC button until the timeout, and maybe dont bother with checking if self.get_cart_count() == 0 and early exit ? what do you guys suggest?

image

image

DakkJaniels commented 3 years ago

Then it will sit there for 5-10 seconds until the timeout occurs, which also not something you would want to happen. Probably makes sense to just set a flag once it hits it the first time, then waits a half a second before it breaks the loop.

sircambridge commented 3 years ago

happened again on june 26th. I thought I had removed the get_cart_count, but i had not. I'm going to remove it and report back in a few weeks

image