我启动服务器,它转到网页index.html。网页上有一个按钮。我想单击此按钮并启动gotest.js,它将启动测试(如loginTest.js )。我该怎么做呢?
server.js:
var express = require("express");
var path = require("path");
var app = express();
app.get("/", function(req, res) {
res.sendFile(__dirname + "index.html");
});
app.listen(1234);
console.log("Server has started!");index.html:
<button>Launch Selenium Autotest</button> // or any another HTML-elementgotest.js:
const { loginTest } = require("loginTest");
const autotest = async () => {
await loginTest();
};
try {
autotest();
} catch (e) {
console.log(e);
}loginTest.js:
const { By, Key, until } = require("selenium-webdriver");
const webdriver = require("selenium-webdriver");
require("chromedriver");
module.exports = {
loginTest: async () => {
let driver = await new webdriver.Builder().forBrowser("chrome").build();
driver.manage().window().maximize();
try {
await driver.get("https://www.youtube.com/");
console.log("DONE");
} catch (e) {
console.log(e);
} finally {
await driver.quit();
}
}
};发布于 2020-03-08 14:45:13
将id和js文件放在点击按钮上运行
<button onclick="gotest.js" id="btnmodal" data-modal="btnmodal">Launch yourFirstJS file</button>将此脚本放在标题中,是否应在页面加载时自动单击上面的按钮
<script>
jQuery(function(){
jQuery('#btnmodal').click();
});
</script>希望这能有所帮助
https://stackoverflow.com/questions/60546399
复制相似问题