Все работает до момента загрузки файла. Это автоматизация загрузки файла с собственным уникальным путем к файлу. Я использую данные из загружаемого файла CSV, чтобы создать уникальный путь к файлу для каждого экземпляра цикла. Каждый раз я получаю следующую ошибку: FileChooser.set_files: ENOENT: нет такого файла или каталога, доступ к '/Users/dani/Library/CloudStorage/OneDrive-Personal/MCS-150 (Reactivate)/123456/Screenshot-2024 -09-15-at-2.16.42 AM.png
from playwright.sync_api import sync_playwright
import time
import csv
file_path = '/Users/dani/Library/CloudStorage/OneDrive-Personal/Jotform Downloads/Jotform_Reactivate_Submissions.csv'
with open(file_path, 'r') as file:
csv_reader = csv.reader(file)
next(csv_reader)
for line in csv_reader:
with sync_playwright() as p:
browser = p.webkit.launch(headless=False, args=["--start-maximized"])
page = browser.new_page(no_viewport=True)
page.goto("https://ask.fmcsa.dot.gov/app/ticket")
page.set_default_timeout(60000)
page.wait_for_load_state('networkidle')
page.locator('xpath=//*[@id="rn_TextInput_5_Contact.Emails.PRIMARY.Address"]').fill('building.wealth@icloud.com')
page.locator('xpath=//*[@id="rn_TextInput_7_Contact.Name.First"]').fill(line[0])
page.locator('xpath=//*[@id="rn_TextInput_9_Contact.Name.Last"]').fill(line[1])
page.locator('xpath=//*[@id="rn_TextInput_11_Incident.CustomFields.c.dot_number"]').fill(line[2])
page.locator('xpath=//*[@id="rn_TextInput_13_Incident.CustomFields.c.mc_number"]').fill(line[3])
page.locator('xpath=//*[@id="rn_ProductCategoryInputSimpleFiltered_20_Incident.Product_lvl1"]').select_option('USDOT Number')
page.locator('xpath=//*[@id="rn_ProductCategoryInputSimpleFiltered_20_Incident.Product_lvl2"]').select_option('Reactivate my USDOT Number')
time.sleep(15)
ID_path = ('/Users/dani/Library/CloudStorage/OneDrive-Personal/MCS-150 (Reactivate)/{}/{}'.format(line[2], line[4]))
LLC_path = ('/Users/dani/Library/CloudStorage/OneDrive-Personal/MCS-150 (Reactivate)/{}/{}'.format(line[2], line[5]))
print(ID_path)
print(LLC_path)
with page.expect_file_chooser() as fc_info:
page.get_by_label("Attach Documents").click()
file_chooser = fc_info.value
file_chooser.is_multiple()
file_chooser.set_files(ID_path)
time.sleep(10)
file_chooser.set_files(LLC_path)
time.sleep(30)
browser.close()
Код будет работать, если я вручную введу путь к файлу, например, но, конечно, я не хочу, чтобы он повторялся по тому же пути к файлу.
from playwright.sync_api import sync_playwright
import time
import csv
file_path = '/Users/dani/Library/CloudStorage/OneDrive-Personal/Jotform Downloads/Jotform_Reactivate_Submissions.csv'
with open(file_path, 'r') as file:
csv_reader = csv.reader(file)
next(csv_reader)
for line in csv_reader:
with sync_playwright() as p:
browser = p.webkit.launch(headless=False, args=["--start-maximized"])
page = browser.new_page(no_viewport=True)
page.goto("https://ask.fmcsa.dot.gov/app/ticket")
page.set_default_timeout(60000)
page.wait_for_load_state('networkidle')
page.locator('xpath=//*[@id="rn_TextInput_5_Contact.Emails.PRIMARY.Address"]').fill('building.wealth@icloud.com')
page.locator('xpath=//*[@id="rn_TextInput_7_Contact.Name.First"]').fill(line[0])
page.locator('xpath=//*[@id="rn_TextInput_9_Contact.Name.Last"]').fill(line[1])
page.locator('xpath=//*[@id="rn_TextInput_11_Incident.CustomFields.c.dot_number"]').fill(line[2])
page.locator('xpath=//*[@id="rn_TextInput_13_Incident.CustomFields.c.mc_number"]').fill(line[3])
page.locator('xpath=//*[@id="rn_ProductCategoryInputSimpleFiltered_20_Incident.Product_lvl1"]').select_option('USDOT Number')
page.locator('xpath=//*[@id="rn_ProductCategoryInputSimpleFiltered_20_Incident.Product_lvl2"]').select_option('Reactivate my USDOT Number')
time.sleep(15)
ID_path = ('/Users/dani/Library/CloudStorage/OneDrive-Personal/MCS-150 (Reactivate)/{}/{}'.format(line[2], line[4]))
LLC_path = ('/Users/dani/Library/CloudStorage/OneDrive-Personal/MCS-150 (Reactivate)/{}/{}'.format(line[2], line[5]))
print(ID_path)
print(LLC_path)
with page.expect_file_chooser() as fc_info:
page.get_by_label("Attach Documents").click()
file_chooser = fc_info.value
file_chooser.is_multiple()
file_chooser.set_files('/Users/dani/Library/CloudStorage/OneDrive-Personal/MCS-150 (Reactivate)/123456/Screenshot-2024-09-15-at-2.16.42 AM.png')
time.sleep(10)
file_chooser.set_files('/Users/dani/Library/CloudStorage/OneDrive-Personal/MCS-150 (Reactivate)/123456/IMAGE-2024-09-1-at-2.16.55 AM.png')
time.sleep(30)
browser.close()
Подробнее здесь: https://stackoverflow.com/questions/792 ... -a-file-er
Получение следующей ошибки в Playwright (Python) при попытке загрузить файл: Ошибка: ENOENT: нет такого файла или катало ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение