playwright-python

Converting request interception example from Cypress to Playwright Python

Converting request interception example from Cypress to Playwright Python Question: The Cypress project has a sample test on how to intercept and modify AJAX calls and I wanted to rewrite the same example in Playwright for Python (pytest). The example consists on intercepting and modifying an Ajax call that feeds the Comments section of a …

Total answers: 1

Pause the main thread during the execute callback function

Pause the main thread during the execute callback function Question: I am trying to use page.on to listening certain event, and once it is triggered I want to use callback function to handle it and pause the main thread operation till the callback finished. How can I achieve that? So far it is what I …

Total answers: 1

Expect value of a dropdown select based on option text

Expect value of a dropdown select based on option text Question: We have a dropdown select <select id="favorite-colors" multiple> <option value="R">Red</option> <option value="G">Green</option> <option value="B">Blue</option> </select> In playwright we can use to check the value expect(locator).to_have_values([re.compile(r"R"), re.compile(r"G")]) See: https://playwright.dev/python/docs/api/class-locatorassertions#locator-assertions-to-have-values But how can I use the expect to check if the selection is "Red" or "Green" …

Total answers: 2

Python playwright unable to access elements

Python playwright unable to access elements Question: I want to scrape the words which reside in the <li> elements. The results return an empty list. Are they resided within a frame because as I can see they are not within any <iframe><iframe> elements? If they do how do you access the frame or find the …

Total answers: 2

Why playwright miss pattern url?

Why playwright miss pattern url? Question: I need to handle request with certain url and im trying to do it like this: await page.route("**/api/common/v1/play?**", handle_data_route) But it also handles a url like this: api/common/v1/play_random? Asked By: kshnkvn || Source Answers: Try using a regular expression instead await page.route(/^.*/api/common/v1/play?.*$/, handle_data_route) Answered By: noah1400

Total answers: 1

Scrapy Crawl (referer: None)

Scrapy Crawl (referer: None) Question: I am new to scrapy and python I am scrapping data from Aliexpress.com with playwright method and it returns (referer: None): Here is my code class AliSpider(scrapy.Spider): name = "aliex" def start_requests(self): # GET request search_value = ‘phones’ yield scrapy.Request(f"https://www.aliexpress.com/premium/{search_value}.html?spm=a2g0o.productlist.1000002.0&initiative_id=SB_20230118063054&dida=y", meta=dict( playwright= True, playwright_include_page = True, playwright_page_coroutines =[ PageMethod(‘wait_for_selector’, ‘.list–gallery–34TropR’) …

Total answers: 1

Python Playwright start maximized window

Python Playwright start maximized window Question: I have a problem starting Playwright in Python maximized. I found some articles for other languages but doesn’t work in Python, also nothing is written about maximizing window in Python in the official documentation. I tried browser = p.chromium.launch(headless=False, args=["–start-maximized"]) And it starts maximized but then automatically restores back …

Total answers: 4

How to open multiple persistent chrome profiles using playwright

How to open multiple persistent chrome profiles using playwright Question: I have some Chrome profiles in which I have my different accounts logged in. I’m writing a multi-threaded script that will run each profile using launch_persistent_context so that I’m already logged in and script starts working from thereon. I’m using Playwright, on Windows 10. Here’s …

Total answers: 1

playwright doesn't respond with systemctl service

playwright doesn't respond with systemctl service Question: My server is running on Ubuntu 22.04.1 LTS and I have a python flask app which runs perfectly with an active virtual environment (source bin/activate) using wsgi [python 3.10]. While all my other routes are working fine, I can’t make playwright related routes run using systemctl service. For …

Total answers: 1

Get element text behind shadow DOM element using Playwright

Get element text behind shadow DOM element using Playwright Question: I am trying to use Playwright to get contents of the open shadow root element which looks like this. <some-element> #shadow-root ABC </some-element> Here #shadow-root contains text ABC without any additional tags. I am able to locate some-element but I cannot find a way to …

Total answers: 2