gpt4 book ai didi

javascript - 我正在尝试使用 selenium-webdriver 截取元素的屏幕截图,但抛出了 UnsupportedOperationError?

转载 作者:行者123 更新时间:2023-11-29 16:08:01 31 4
gpt4 key购买 nike

我当前的代码如下所示。

var webdriver = require('selenium-webdriver'),
until = webdriver.until,
By = webdriver.By,
fs = require('fs');

var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();

driver.get('https://www.google.com/');

driver.findElement(By.css('#hplogo')).then((el) => {
el.takeScreenshot().then((data) => {
var base64Data = data.replace(/^data:image\/png;base64,/, "");
fs.writeFile(__dirname + "/out.png", base64Data, 'base64', (err) => {
if(err) console.log(err);
});
});
});

当我运行它时,我收到错误消息:

/home/project/node_modules/selenium-webdriver/lib/promise.js:654
throw error;
^

UnsupportedOperationError: unknown command: session/797c146086bc89ad245f76ce99302a48/element/0.9715665113180876-1/screenshot
at WebDriverError (/home/project/node_modules/selenium-webdriver/error.js:26:26)
at UnsupportedOperationError (/home/project/node_modules/selenium-webdriver/error.js:435:26)
at Object.checkLegacyResponse (/home/project/node_modules/selenium-webdriver/error.js:578:13)
at /home/project/node_modules/selenium-webdriver/lib/webdriver.js:360:15
at Promise.invokeCallback_ (/home/project/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/home/project/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/home/project/node_modules/selenium-webdriver/lib/promise.js:2773:21)
at /home/project/node_modules/selenium-webdriver/lib/promise.js:2652:27
at /home/project/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (node.js:406:9)

我使用的是 selenium-webdriver 2.52.0 版。有人知道出了什么问题吗?

最佳答案

确认@Andersson 所说的内容,Microsoft Edge(reference)除外,no WebDriver actually implements element-based screenshots .您必须生成全屏屏幕截图并进行裁剪。

参见 my earlier answer有关此主题(和其他主题)的更多背景信息和解决方法。

关于javascript - 我正在尝试使用 selenium-webdriver 截取元素的屏幕截图,但抛出了 UnsupportedOperationError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36084257/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com