В настоящее время я пытаюсь автоматизировать экспорт любимых gif-файлов Discord.
У меня есть этот фрагмент:
window.FrecencyUserSettings ??= webpackChunkdiscord_app.push([[Symbol()],,e=>Object.values(e.c).values().map(m=>m.exports).filter(x=>typeof x=="object"&&x!=window&&x!=DOMTokenList.prototype).flatMap(x=>[x,...Object.values(x)]).find(x=>!x?.$$loader&&x?.ProtoClass?.typeName?.endsWith(".FrecencyUserSettings"))]);
function downloadJSON(content, download) {
const json = JSON.stringify(content, null, 2);
Object.assign(document.createElement("a"), {
href: URL.createObjectURL(new Blob([json], { type: "application/json" })),
download
}).click();
}
FrecencyUserSettings.loadIfNecessary();
downloadJSON(FrecencyUserSettings.getCurrentValue().favoriteGifs.gifs, "discord-favorite-gifs.json");
Он отлично работает в консоли браузера, но когда я запускаю его через Selenium, я получаю следующую ошибку:
Необработанное исключение. OpenQA.Selenium.JavaScriptException: TypeError: невозможно получить доступ к свойству "gifs", FrecencyUserSettings.getCurrentValue().favoriteGifs не определено
Вот мой код C# для автоматизации браузера:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace exportGifs;
class Program {
static void Main(string[] args) {
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("https://discord.com/app");
Console.WriteLine("please sign into discord, press enter when you've done so");
while (Console.ReadKey(intercept: true).Key != ConsoleKey.Enter) {
}
IJavaScriptExecutor javaScriptExecutor = (IJavaScriptExecutor)driver;
var script = File.ReadAllText("gifs.js");
if (driver.Url == "https://discord.com/channels/@me") {
javaScriptExecutor.ExecuteScript(script);
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... n-selenium