We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用webdriverio来进行自动化 这一块代码放在controller里面一直获取不到元素, ` const { ctx, app } = this; // 第一步获取预测服务的信息
const browser = await remote({ capabilities: { browserName: 'chrome', 'goog:chromeOptions': { binary: path.join(__dirname, '../../chrome/Application/chrome.exe'), // args: process.env.CI ? ['headless', 'disable-gpu'] : [] }, 'wdio:chromedriverOptions': { // or 'wdio:geckodriverOptions', 'wdio:edgedriverOptions' binary: path.join(__dirname, '../../chromedriver.exe'), } } }) await browser.url('https://www.baidu.com/'); const inputElem = await browser.$(`//*[@id="kw"]`); console.log(11111111111111, inputElem); await inputElem.setValue('WebdriverIO'); this.ctx.body = 'Success';
}但是在schedule 定时模块里面执行就可以获取的到onst { remote } = require('webdriverio'); const path = require("path"); module.exports = (app) => { return { schedule: { interval: '10s', // 30分钟间隔codee type: 'worker', // 指定所有的 worker 都需要执行 disable: true, }, async task(ctx) { const browser = await remote({ capabilities: { browserName: 'chrome', 'goog:chromeOptions': { binary: path.join(__dirname, '../../chrome/Application/chrome.exe'), // args: process.env.CI ? ['headless', 'disable-gpu'] : [] }, 'wdio:chromedriverOptions': { // or 'wdio:geckodriverOptions', 'wdio:edgedriverOptions' binary: path.join(__dirname, '../../chromedriver.exe'), } } }) await browser.url('https://www.baidu.com/') const inputElem = await browser.$(//*[@id="kw"]) console.log(11111111111111, inputElem) await inputElem.setValue('WebdriverIO') }, };
但是在schedule 定时模块里面执行就可以获取的到
//*[@id="kw"]
},尝试在express服务里面调用也可以成功,const express = require('express') const { remote } = require('webdriverio'); const path = require("path"); const app = express() const port = 3000 app.get('/api', async (req, res) => { const browser = await remote({ capabilities: { browserName: 'chrome', 'goog:chromeOptions': { binary: path.join(__dirname, '/chrome/Application/chrome.exe'), }, 'wdio:chromedriverOptions': { binary: path.join(__dirname, '/chromedriver.exe'), }, }, });
,尝试在express服务里面调用也可以成功,
try { await browser.navigateTo('https://www.baidu.com/'); const inputElem = await browser.$(`//*[@id="kw"]`) if (!inputElem) { console.error('Element not found'); return; } await inputElem.setValue('WebdriverIO'); const submitBtn = await browser.$('//*[@id="su"]'); await submitBtn.click(); } catch (error) { console.error('WebdriverIO Error:', error); } finally { // await browser.deleteSession(); }
})
app.listen(port, () => { console.log(Example app listening on port ${port}) })并且在单独文件直接用node执行也可以调用成功const { remote } = require('webdriverio');
Example app listening on port ${port}
并且在单独文件直接用node执行也可以调用成功
(async () => { const browser = await remote({ capabilities: { browserName: 'chrome', 'goog:chromeOptions': { binary: './chrome/Application/chrome.exe', // args: process.env.CI ? ['headless', 'disable-gpu'] : [] }, 'wdio:chromedriverOptions': { // or 'wdio:geckodriverOptions', 'wdio:edgedriverOptions' binary: './chromedriver.exe' // or 'geckodriver', 'msedgedriver' } } }) await browser.url('https://www.baidu.com/') const inputElem = await browser.$(//*[@id="kw"]) console.log(11111111111111,inputElem) await inputElem.setValue('WebdriverIO') // const submitBtn = await browser.$(//*[@id="su"]) // // browser.closeWindow(); // await submitBtn.click(); })() `
//*[@id="su"]
[](
18.0.0
2.37.0
"webdriverio": "^8.26.1"
window11 家庭版
The text was updated successfully, but these errors were encountered:
刚才试了一下在controller 执行 await this.app.runSchedule('test'); 也获取不到
Sorry, something went wrong.
controller是正常的吗,controller位置会不会搞错了,没按约定的目录形式导致没加载到controller
控制器是正常的吗,控制器位置会不会搞错了,未按约定的目录格式导致未加载到控制器
没错,我之前用的selenium去实现的,这次换webdriverio,项目结构都没变,浏览器都能打开,页面也出来了,就是获取不到元素
No branches or pull requests
在此输入你需要反馈的 Bug 具体信息(Bug in Detail):
使用webdriverio来进行自动化
这一块代码放在controller里面一直获取不到元素,
` const { ctx, app } = this;
// 第一步获取预测服务的信息
}
但是在schedule 定时模块里面执行就可以获取的到
onst { remote } = require('webdriverio');const path = require("path");
module.exports = (app) => {
return {
schedule: {
interval: '10s', // 30分钟间隔codee
type: 'worker', // 指定所有的 worker 都需要执行
disable: true,
},
async task(ctx) {
const browser = await remote({
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
binary: path.join(__dirname, '../../chrome/Application/chrome.exe'),
// args: process.env.CI ? ['headless', 'disable-gpu'] : []
},
'wdio:chromedriverOptions': { // or 'wdio:geckodriverOptions', 'wdio:edgedriverOptions'
binary: path.join(__dirname, '../../chromedriver.exe'),
}
}
})
await browser.url('https://www.baidu.com/')
const inputElem = await browser.$(
//*[@id="kw"]
)console.log(11111111111111, inputElem)
await inputElem.setValue('WebdriverIO')
},
};
}
,尝试在express服务里面调用也可以成功,
const express = require('express')const { remote } = require('webdriverio');
const path = require("path");
const app = express()
const port = 3000
app.get('/api', async (req, res) => {
const browser = await remote({
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
binary: path.join(__dirname, '/chrome/Application/chrome.exe'),
},
'wdio:chromedriverOptions': {
binary: path.join(__dirname, '/chromedriver.exe'),
},
},
});
})
app.listen(port, () => {
console.log(
Example app listening on port ${port}
)})
并且在单独文件直接用node执行也可以调用成功
const { remote } = require('webdriverio');(async () => {
const browser = await remote({
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
binary: './chrome/Application/chrome.exe',
// args: process.env.CI ? ['headless', 'disable-gpu'] : []
},
'wdio:chromedriverOptions': { // or 'wdio:geckodriverOptions', 'wdio:edgedriverOptions'
binary: './chromedriver.exe' // or 'geckodriver', 'msedgedriver'
}
}
})
await browser.url('https://www.baidu.com/')
const inputElem = await browser.$(
//*[@id="kw"]
)console.log(11111111111111,inputElem)
await inputElem.setValue('WebdriverIO')
// const submitBtn = await browser.$(
//*[@id="su"]
)// // browser.closeWindow();
// await submitBtn.click();
})()
`
可复现问题的仓库地址(Reproduction Repo)
[](
Node 版本号:
18.0.0
Eggjs 版本号:
2.37.0
相关插件名称与版本号(PlugIn and Name):
"webdriverio": "^8.26.1"
操作平台与版本号(Platform and Version):
window11 家庭版
The text was updated successfully, but these errors were encountered: