我需要使用函数验证元素是否在屏幕上。如果没有,它将执行另一个功能。例如:
- description: validation function
script: |
$runAction("org.getopentest.selenium.NavigateTo", {
url: "https://translate.google.com/"
}),;
if((
$runAction('org.getopentest.selenium.AssertElementVisible',
{
"locator": {css: "[id='sugg-item-en']"},
})
) == 'true'){
} else {
$runAction('org.getopentest.selenium.AssertElementVisible',
{
"locator": {css: "[id='sugg-item-pt']"}
});
}
您可以使用try...catch
语句:
- description: Validation function
script: |
try {
$runAction('org.getopentest.selenium.AssertElementVisible', {
"locator": {css: "[id='sugg-item-en']"},
});
// If element was found (the assert succeeded), execution continues here
} catch {
// If element was NOT found (the assertion failed), execution continues here
}