javascript - 在 Selenium 中打开测试页面
问题描述
我开始使用 Selenium,所以我创建(我认为)是一个快速测试脚本,可以简单地在我公司的 Intranet 中打开一个页面。
我不确定我应该在哪里下载 Selenium 的依赖项,所以我在我的开发服务器上创建了一个名为“TESTING”的文件夹,并使用命令提示符安装 Selenium:
npm install selenium-webdriver
安装似乎是成功的,因为它显示“添加了来自 79 个贡献者的 46 个包......”
在我的 TESTING 目录中,我可以看到添加了 node_modules 目录以及 package-lock.json 文件。
然后我创建了一个 index.php 文件,它只有以下内容:
<h1>hello world</h1>
<button type="submit" name="btnI">Click Me</button>
这里是 sample.js,它包括以下应该打开 index.php 的脚本:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get("https://development.usa.company.com/testing/index.php");
driver.findElement(webdriver.By.name('btnI')).click();
我回到 cmd 提示符并运行以下命令:
node sample.js
我收到以下错误:
Error: The ChromeDriver could not be found on the current PATH.
Please download the latest version of the ChromeDriver from
http://chromedriver.storage.googleapis.com/index.html
and ensure it can be found on your PATH.
我究竟做错了什么?
解决方案
看起来您需要将 PATH 添加chromedriver.exe
到系统环境变量中。
- 安装 chromedriver.exe -- 注意安装目录的文件路径
- 在 Windows 中搜索
Environment Variables
并单击“环境变量..”进行编辑 - 编辑“路径”变量
- 在出现所有其他文件路径后,添加“C:\Path\To\ChromeDriver\Directory\chromedriver.exe”,用分号与其他路径分隔。
推荐阅读
- html - HTML Dom 在 FORM 外显示 INPUT
- java - axios.post("/checkitem/add.do",this.formData).then((res)....得到 404
- flutter - 具有共享偏好的 Flutter Switch 在第一次更改时不起作用
- ios - 显示EditText的键盘后视图不滚动(在键盘下编辑文本)SwiftUI
- node.js - Google Speech Adaptation Client (node.js) - UnhandledPromiseRejectionWarning:错误:13 内部:遇到内部错误
- python - 将情节静态图像生成从逆戟鲸更改为万花筒
- node.js - 如何在 Elasticsearch 中为文件夹中的每个文件获取一个新的 JSON 条目
- ios - 为什么我们可以将 flatMap 链接到 UserDefaults.standard.data
- excel - Excel中的外部引用字符串仅在从开头删除'后才变为公式,为什么以及如何重复数百次?
- python - TypeError:recognize() 接受 1 到 2 个位置参数,但给出了 3 个