问题描述
该功能应该打开链接(这是一个adfly链接),等待计时器完成,然后单击“跳过广告”,等待直到youtube页面刷新,然后加载<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<button>Open Dialog</button>
<div id="dgReport" title="Basic dialog">
<p>This is the default dialog which is useful for displaying @R_141_4045@ion. The dialog window can be moved,resized and closed with the 'x' icon.</p>
</div>
并关闭浏览器。但是,exit(start);
无法运行。
这是我正在使用的功能。一些帮助将不胜感激!
browser.quit();
function test(start){
(async function init() {
let driver = await new Builder().forbrowser('firefox').build();
try{
// Navigate to Url
await driver.get('http://raboninco.com/KY6z');
await new Promise(resolve => setTimeout(resolve,8000));
var click_skip = driver.findElement(By.id('skip_bu2tton')).click();
await new Promise(resolve => setTimeout(resolve,19000));
}
finally{
driver.quit();
exit(start);
}
})();
}
我能得到的任何帮助都会很可爱!谢谢。
解决方法
我运行了代码,看来driver.quit()起作用了。您的问题是console.log行中的自定义退出功能:
- 什么是成功?
- 什么是错误?
此外,您的代码似乎缺少一些元素,因此我对其进行了一些修复:
const {Builder,By,until} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
function test(start){
(async function init() {
let driver = await new Builder().forBrowser('firefox').build();
try{
// Navigate to Url
await driver.get('http://raboninco.com/KY6z');
await new Promise(resolve => setTimeout(resolve,8000));
await driver.wait(until.elementLocated(By.id('skip_bu2tton')),1000); //wait for element to appear if it doesnt appear selenium throws error
var click_skip = await (await driver.findElement(By.id('skip_bu2tton'))).click(); // find element is async and also click is async so you need to add await
await new Promise(resolve => setTimeout(resolve,19000));
}catch(err){ // all the code above can throw errors you need to catch them
console.log(err);
}
finally{
await driver.quit();
exit(start);
}
})();
}
function exit(start){
var time = Date.now() - start;
//add a correct console.log for example console.log(`Finished,time -${ time / 1000 }`)
process.exit();
}
test(Date.now());