Skip to content

Make troubleshooting click() failures easier#11

Open
pboushy wants to merge 4 commits intomainfrom
make-troubleshooting-click-failures-easier
Open

Make troubleshooting click() failures easier#11
pboushy wants to merge 4 commits intomainfrom
make-troubleshooting-click-failures-easier

Conversation

@pboushy
Copy link
Collaborator

@pboushy pboushy commented Sep 22, 2025

In my most recent run, I kept running into a problem where it would crash immediately.

Since I've seen this in the past, I looked at ways to make it easier for a user/developer to investigate the webpage in the browser that playwright opens.

Because multiple different functions are used to locate the item to click, I decided to create a single wrapper function safe_click() that takes the name of a page method, and the respective arguments.

This makes it very easy for anyone to run the amazon-invoice-downloader with the --debug flag, see the web interface, right click > inspect and determine what the issue is. It should make it far easier to make adjustments as Amazon changes their website.

 * Add a --debug flag to keep the browser open on failure
 * Add safe_click function to wrap click actions with error handling
@pboushy pboushy requested a review from dcwangmit01 September 22, 2025 00:39
@pboushy pboushy mentioned this pull request Sep 22, 2025
* get_by_role isn't truthy; check count or visibility
* query_selector returns an object or None
* Use page.title() method instead of query_selector
* Use wait_for_selector() instead of checking if still on page
* Check if there's a next link instead of waiting for it to timeout
* Add message to make it clear script is done
Copy link
Owner

@dcwangmit01 dcwangmit01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pboushy Thanks for making a PR! I appreciate it. I thought I'd add some comments. I'll give you a few days to address the comments. If you don't get to it, I'll merge it anyways. Happy holidays.

# Check if we're on the less fully featured page
test_less_featured_page = page.query_selector('a:has-text("Returns & Orders")')
if not test_less_featured_page:
if test_less_featured_page is None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NITPICK: I think some of my old teammates would have said this is less Pythonic. I'm not the Python police, though. Just FYI.



def amazon_invoice_downloader():
global DEBUG_MODE
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MUST: Would be great to avoid a global variable. This program uses "docopt" library, so you it should automatically be passed in at L342 in your PR. "run(playwright, args)"

@pboushy
Copy link
Collaborator Author

pboushy commented Dec 16, 2025

I'll work on this over the weekend. I didn't get to it last weekend due to some personal items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants