![](/img/trans.png)
[英]Run Selenium Commands For Zalenium from another Docker Container
[英]Selenium on a Docker container
我有一個簡單的 javascript 文件,它使用 selenium 啟動 Chrome,打開一些網站,並從該網站收集一些數據。 現在,我想將該文件放入 Docker 容器中並運行它。
為此,我編寫了以下Dockerfile :
FROM alpine
RUN apk add --update nodejs npm chromium
COPY . /src
WORKDIR /src
RUN npm install -g chromedriver
RUN npm install
ENTRYPOINT ["node", "index.js"]
圖像構建沒有錯誤,但是當我嘗試從中運行容器時,我得到:
/src/node_modules/selenium-webdriver/remote/index.js:248
reject(Error(e.message))
^
Error: Server terminated early with status 1
at /src/node_modules/selenium-webdriver/remote/index.js:248:24
at processTicksAndRejections (node:internal/process/task_queues:96:5)
我的 index.js 文件只有一個依賴項 - "selenium-webdriver": "^4.1.1"
,文件本身如下所示:
index.js
const {Builder, By} = require('selenium-webdriver');
(async function example() {
let driver = await new Builder().forBrowser('chrome').build();
try {
// Navigate to Url
await driver.get('https://www.example.com');
// Get all the elements available with tag 'p'
let elements = await driver.findElements(By.css('p'));
for(let e of elements) {
console.log(await e.getText());
}
}
finally {
await driver.quit();
}
})();
我究竟做錯了什么? 如何讓容器成功運行?
同樣的問題,我認為是與 selenium-webdriver/chrome 因為構建器被卡在了我的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.