0

我需要使用函数验证元素是否在屏幕上。如果不是,它执行另一个功能。例如:

      - 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']"}
              });
              }
4

1 回答 1

0

您可以使用以下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
      }
于 2020-03-18T18:08:02.043 回答