如何使用html按钮运行javascript selenium函数?
这段代码工作得很好,但我需要在一个html按钮上运行这个脚本,这意味着当按钮被点击时,这个函数就会被执行如何使用html按钮运行javascript selenium函数?,javascript,Javascript,这段代码工作得很好,但我需要在一个html按钮上运行这个脚本,这意味着当按钮被点击时,这个函数就会被执行 async function example() { let driver = await new Builder().forBrowser("chrome").build(); await driver.get("https://google.com"); } example(); 我试过了,但没用 <!DOCTYPE html> <html lan
async function example() {
let driver = await new Builder().forBrowser("chrome").build();
await driver.get("https://google.com");
}
example();
我试过了,但没用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Javascript Testing</title>
</head>
<body>
<script type="text/Javascript">
async function example()
{
const {Builder, By, Key, util} = require("selenium-webdriver")
let driver = new Builder().forBrowser("chrome").build();
driver.get("https://google.com");
driver.findElement(By.name("q")).sendKeys("Selenium",KEY.RETURN);
}
</script>
<button onClick="example()">Click me</button>
</body>
</html>
而且,我还尝试了外部js,但它仍然不工作selenium webdriver无法在web浏览器中运行,它需要的API不可用 您需要重写JS,使其在Node.JS中运行 如果您想从web浏览器访问它,那么您需要为它编写一个web服务前端 然后,您可以通过浏览器访问该web服务,例如,
fetch
index.html Uncaught ReferenceError: example is not defined
at HTMLButtonElement.onclick