Может ли селен запускаться с триггера веб-страницы?
Не веб-драйвер Selenium, а Selenium IDE тесты можно запускать с веб-сайта. Это работает с kantu ide (другой проект), но не с оригинальным ide. Вы можете запустить тест с веб-сайта, добавив на него небольшой фрагмент кода Javascript (см. Ниже). Затем этот фрагмент говорит расширению запустить тестовый пример.
Вот тестовая страница с несколькими встроенными тестами:
https://a9t9.com/kantu/demo/runweb
Чтобы запустить этот тест, сначала необходимо разрешить его в настройках Kantu. Если вы не разрешите запускать встроенные макросы, Kantu покажет диалоговое окно с сообщением об ошибке по соображениям безопасности.
function RunMacro1() {
// Embedded Kantu Macros V3.60, License: MIT License (Open-Source)
//This code snippet checks if Kantu is installed, and if yes, tells Kantu to import and run the macro.
//In Kantu itself the user can allow/not allow to run embedded web macros (OFF by default)
//To run web macros from specific websites without warning prompt, they URLs of certain websites can be whitelisted
//For more details please see https://a9t9.com/kantu/docs#embed
(function (detail) {
var isExtensionLoaded = function () {
var $root = document.documentElement
return !!$root && !!$root.getAttribute('data-kantu')
}
var openExternal = function (url) {
const $el = document.createElement('a')
$el.setAttribute('target', '_blank')
$el.setAttribute('href', url)
$el.style.position = 'absolute'
$el.style.top = '-9999px'
$el.style.left = '-9999px'
document.body.appendChild($el)
$el.click()
setTimeout(() => {
$el.remove()
}, 200)
}
var openWebsite = function () {
openExternal('https://a9t9.com/kantu/')
}
if (!isExtensionLoaded()) {
if (confirm('Kantu is not installed yet. Do you want to download Kantu now?')) {
return openWebsite()
}
} else {
return window.dispatchEvent(new CustomEvent('kantuSaveAndRunMacro', { detail: detail }))
}
})
({
direct: true, //If the website URL is whitelisted, run the macro without prompt
json: {
//Macro JSON code here. You can copy and paste the code directly from the Kantu source tab, https://a9t9.com/kantu/docs#sourcecodetab
"Name": "EmbeddedMacro_FillOutGoogleForm",
"CreationDate": "2018-11-25",
"Commands": [
{
"Command": "bringBrowserToForeground",
"Target": "",
"Value": ""
},
{
"Command": "open",
"Target": "https://docs.google.com/forms/d/11UBhaBf-clTy_EiI6TjlxaAinhae3rvPaPqS14epAfA/viewform?edit_requested=true",
"Value": ""
},
{
"Command": "type",
"Target": "name=entry.933434489",
"Value": "This is just test data"
},
{
"Command": "type",
"Target": "name=entry.1382578664",
"Value": "testonly@a9t9.com"
},
{
"Command": "type",
"Target": "name=entry.336178899",
"Value": "You find this embedded macro INSIDE the web page"
},
{
"Command": "clickAndWait",
"Target": "//*[@id=\"mG61Hd\"]/div/div[2]/div[3]/div[1]/div/div/content/span",
"Value": ""
}
]
}
})
}