'My playwright generated code doesn't work

I have genarated a code using an extension in google chrome in order to automate some actions on aliexpress website with the use of playwright. But while running my code I get this error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\aicha\Desktop\selenium_ide\playwright.py", line 1, in <module>
    from playwright.sync_api import Playwright, sync_playwright, expect
ModuleNotFoundError: No module named 'playwright.sync_api'; 'playwright' is not a package

here is the script that I have written :

from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://www.aliexpress.com/")
    page.locator("._24EHh").click()
    page.locator(".close-btn").click()
    page.locator("text=MAD 40.41Orders over MAD 50.51May 17, 02:05 AM PT - May 24, 02:05 AM PTClaim now >> img").nth(1).click()
    page.locator("#switcher-info").click()
    page.locator("a:has-text(\"Morocco\")").click()
    page.locator("[placeholder=\"Search\"]").first.click()
    page.locator("[placeholder=\"Search\"]").first.fill("Spain")
    page.locator("li:has-text(\"Spain\")").click()
    page.locator("span:has-text(\"Español\")").click()
    page.locator("text=English").nth(1).click()
    page.locator("span:has-text(\"EUR ( Euro )\")").click()
    page.locator("text=EUR ( Euro ) CHF ( Swiss Franc ) MXN ( Mexican Peso ) EUR ( Euro ) CLP ( Chilean >> [placeholder=\"Search\"]").click()
    page.locator("text=EUR ( Euro ) CHF ( Swiss Franc ) MXN ( Mexican Peso ) EUR ( Euro ) CLP ( Chilean >> [placeholder=\"Search\"]").fill("MAD")
    page.locator("text=MAD ( Moroccan Dirham )").click()
    with page.expect_navigation():
        page.locator("text=Save").click()
    context.close()
    browser.close()
with sync_playwright() as playwright:
    run(playwright)

I would be grateful if you help me . Thank you in advance !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source