I'm testing a Chrome extension at work and most of the page elements aren't click-able or visible without using time.sleep() first for about 3 seconds. I'm using locators with xpath. I have a context for my extension that's yielded from conftest.py, inhertied by each pytest function, and then then I generate a new page with page = context.new_page() and navigate to my extension's pop up page like page.goto(chrome://extension_id/ui/popup/popup.index). After that I'm trying to click on a button element on that page. Auto wait doesn't seem to be working and using page.wait_for_element() before clicking the element or expecting it to be visible using expect(element).to_be_visible() doesn't seem to work. My boss doesn't want me to use time.sleep() for obvious flakiness reasons. Have you had to overcome a situation like this using python? How did you get past it?
This thread is trying to answer question "How to interact with page elements without using time.sleep() in playwright-pytest?"
Just simply wait for the locator with element.wait_for() https://playwright.dev/python/docs/release-notes#locatorwait_for
I tried this in inspector last night and it finds and highlights the correct page element. Another thing I noticed is that running things in the inspector always pauses where my script tries to click the "hard-to-find" and highllghts the button without the element.hightlight() or the page.pause(). If I click play in the inspector after that pause it will always find the element (with or without the element.wait_for()) and click it without the time.sleep() but it seems like it's relying on the pause from teh inspector because when I run that same test with just pytest and no time.sleep() (with or without the element.wait_for()), it fails at that point.
Another thing I'm thinking may be causing issues is that when I create the page that has the "hard-to-find-button", it's the first page I'm creating and it always creates two pages. One just stays as a blank tab and the other gets the navigation from page.goto(). It seems like this could be causing problems or is at least worth elminating to narrow things down. I think I read somewhere that creating the extra blank tab with the first page created is a playwright bug.
When I create my first page I do so by using the context that was defined in conftest and inherited as an argument in my test like: page_one = context.new_page() main_page.set_page(page_one) page_one = context.new_page() is what always brings up two tabs with one that always remains blank. Seems like this could cause some problems. main_page.set_page() is where I pass the page object to my main page class which is where I have all my methods that interact with that page.
The issue is here https://github.com/microsoft/playwright/issues/981
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email email@example.com.