gpt4 book ai didi

javascript - 如何点击 webdriverIO 中的链接

转载 作者:行者123 更新时间:2023-12-03 05:25:57 25 4
gpt4 key购买 nike

我正在尝试使用 webdriverIO 单击网页中的链接。我可以导航到 google.com 页面,然后输入搜索词。

但是当我尝试单击包含所需文本的链接时,它不会单击该链接。

我做错了什么:

这是我的代码:

var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
//browserName: 'phantomjs'
browserName: 'chrome'
}
};
webdriverio
.remote(options)
.init()
.url('http://www.google.com')
.setValue('*[name="q"]','webdriverio')
.click('*[name="btnG"]')
.pause(1000)
.getTitle().then(function(title) {
console.log('Title was: ' + title)
})
.getText('=webdriver.io').then(function(text) {
console.log('Title was: ' + text); // outputs: "WebdriverIO"
})
.end();

我正在使用 node.js v6.9.2 和 selenium 独立服务器 3.0.1 运行 webdriverIO。

谢谢。

最佳答案

找到了!!!

用途:

.click('[href="http://webdriver.io/"]')

这种格式对我有用。

关于javascript - 如何点击 webdriverIO 中的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41143369/

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