Я пытаюсь загрузить файл в папку, которой нет в списке управляемых разрешений Playwright. Запустил запрос пользователя на разрешение на редактирование файлов. Я не могу нажать кнопку «Редактировать файлы» с Playwright. Это то, как выглядит диалоговое окно:
Это пример моего приложения.
Create and Save File in Directory
Create and Save File in Directory
Click the button below to select a directory and save a file directly to it.
Save File
document.getElementById("saveFileButton").addEventListener("click", async () => {
try {
// Open the directory picker
const directoryHandle = await window.showDirectoryPicker({mode: "readwrite"});
// Create a new file in the selected directory
const fileHandle = await directoryHandle.getFileHandle("test-file.txt", {
create: true, // Create the file if it doesn't exist
});
// Create a writable stream to write to the file
const writable = await fileHandle.createWritable();
// Write some content to the file
await writable.write("This is a test file created and saved in the selected directory.");
// Close the writable stream
await writable.close();
alert("File saved successfully in the selected directory!");
} catch (error) {
console.error("Error saving file:", error);
alert("An error occurred while saving the file.");
}
});
< /code>
Это код, который проверит приведенную выше страницу < /p>
package com.example.demo;
import com.microsoft.playwright.*;
import org.junit.jupiter.api.*;
public class TestExample {
static Playwright playwright;
static Browser browser;
BrowserContext context;
Page page;
@BeforeAll
static void setupClass() {
playwright = Playwright.create();
browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
}
@AfterAll
static void tearDownClass() {
browser.close();
playwright.close();
}
@BeforeEach
void setup() {
context = browser.newContext();
page = context.newPage();
}
@AfterEach
void tearDown() {
context.close();
}
@Test
void testSaveFileWithAutoIt() throws Exception {
// Navigate to your HTML file
page.navigate("file:///C:/path/test-save-with-picker.html");
// Listen for the alert dialog of file saved sucessfully
page.onceDialog(dialog -> {
System.out.println("Dialog message: " + dialog.message());
dialog.accept();
});
// Run the AutoIt script to set the file download path
Process process = Runtime.getRuntime().exec("C:\\autoit\\set-file-download-path.exe");
page.waitForTimeout(3000);
// Click the button to open the directory picker
page.click("#saveFileButton");
page.waitForTimeout(20000);
int exitCode = process.waitFor(); // Wait for the AutoIt script to complete
if (exitCode == 0) {
System.out.println("AutoIt script executed successfully.");
} else {
System.out.println("AutoIt script failed with exit code: " + exitCode);
}
// I need to auto accept the permission dialog here
и сценарий Autoit < /p>
WinWaitActive("Select where this site can save changes")
ControlSetText("Select where this site can save changes", "","Edit1", "C:\TestDirectory")
Sleep(1000)
ControlClick("Select where this site can save changes", "Select Folder", "Button1")
Подробнее здесь: https://stackoverflow.com/questions/795 ... riggered-b
Как обойти или автоматическое привлечение Chrome. ⇐ Javascript
Форум по Javascript
-
Anonymous
1745606349
Anonymous
Я пытаюсь загрузить файл в папку, которой нет в списке управляемых разрешений Playwright. Запустил запрос пользователя на разрешение на редактирование файлов. Я не могу нажать кнопку «Редактировать файлы» с Playwright. Это то, как выглядит диалоговое окно:
Это пример моего приложения.
Create and Save File in Directory
Create and Save File in Directory
Click the button below to select a directory and save a file directly to it.
Save File
document.getElementById("saveFileButton").addEventListener("click", async () => {
try {
// Open the directory picker
const directoryHandle = await window.showDirectoryPicker({mode: "readwrite"});
// Create a new file in the selected directory
const fileHandle = await directoryHandle.getFileHandle("test-file.txt", {
create: true, // Create the file if it doesn't exist
});
// Create a writable stream to write to the file
const writable = await fileHandle.createWritable();
// Write some content to the file
await writable.write("This is a test file created and saved in the selected directory.");
// Close the writable stream
await writable.close();
alert("File saved successfully in the selected directory!");
} catch (error) {
console.error("Error saving file:", error);
alert("An error occurred while saving the file.");
}
});
< /code>
Это код, который проверит приведенную выше страницу < /p>
package com.example.demo;
import com.microsoft.playwright.*;
import org.junit.jupiter.api.*;
public class TestExample {
static Playwright playwright;
static Browser browser;
BrowserContext context;
Page page;
@BeforeAll
static void setupClass() {
playwright = Playwright.create();
browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
}
@AfterAll
static void tearDownClass() {
browser.close();
playwright.close();
}
@BeforeEach
void setup() {
context = browser.newContext();
page = context.newPage();
}
@AfterEach
void tearDown() {
context.close();
}
@Test
void testSaveFileWithAutoIt() throws Exception {
// Navigate to your HTML file
page.navigate("file:///C:/path/test-save-with-picker.html");
// Listen for the alert dialog of file saved sucessfully
page.onceDialog(dialog -> {
System.out.println("Dialog message: " + dialog.message());
dialog.accept();
});
// Run the AutoIt script to set the file download path
Process process = Runtime.getRuntime().exec("C:\\autoit\\set-file-download-path.exe");
page.waitForTimeout(3000);
// Click the button to open the directory picker
page.click("#saveFileButton");
page.waitForTimeout(20000);
int exitCode = process.waitFor(); // Wait for the AutoIt script to complete
if (exitCode == 0) {
System.out.println("AutoIt script executed successfully.");
} else {
System.out.println("AutoIt script failed with exit code: " + exitCode);
}
// I need to auto accept the permission dialog here
и сценарий Autoit < /p>
WinWaitActive("Select where this site can save changes")
ControlSetText("Select where this site can save changes", "","Edit1", "C:\TestDirectory")
Sleep(1000)
ControlClick("Select where this site can save changes", "Select Folder", "Button1")
Подробнее здесь: [url]https://stackoverflow.com/questions/79593103/how-to-bypass-or-auto-accept-chromes-file-editing-permission-dialog-triggered-b[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия