Katalon执行嵌套的Selenium WebDriver发现

时间:2018-06-13 18:10:08

标签: selenium katalon-studio

我正在尝试在Katalon Studio中的指定<li>中获取所有<ul>。我是通过Selenium WebDriver尝试这个。我有这样的代码:

// login with valid account
WebUI.callTestCase(findTestCase('ValidLogin'), [('shouldCloseBrowser') : false], FailureHandling.STOP_ON_FAILURE)

// get the driver
WebDriver driver = DriverFactory.getWebDriver()

// Loop over selection of each company, and assert that we land on respective dashboard
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS)

WebElement companyListContainer = driver.findElement(By.id('companyList')) 
// finds this element OK


List<WebElement> companies = companyListContainer.findElements(By.xpath('.//li'))
 // this failed

for (int i = 1; i <= companies.length; i++) {
    // click the test object
    driver.findElement(By.xpath('//ul[@id="companyList"]/li[' + i + ']')).click() 
    // implicitly wait 3 seconds
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS) // we better be at the Dashboard page
    // go back to "Company Select"
    WebUI.click(findTestObject('a_Company Select'))
    // wait three seconds again
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS)
}

由于某些原因,即使页面上有<li>List<WebElement>也为空,即使companyListContainer不是,并且包含这些元素。我该如何解决这个问题?

HTML

看起来像:

<ul id="companyList" class="list-group">

    <li class="list-group-item clickable " data--name="EzDine C2 - Michael" data--id="302">
        EzDine C2 - Michael
        <span class="list-check"><i class="fa fa-check text-success" aria-hidden="true"></i></span>
    </li>

    <li class="list-group-item clickable " data--name="EzDine Comp3 -Hos" data--id="303">
        EzDine Comp3 -Hos
        <span class="list-check"><i class="fa fa-check text-success" aria-hidden="true"></i></span>
    </li>

    <li class="list-group-item clickable " data--name="Test EZDine V2 Comp1" data--id="301">
        Test EZDine V2 Comp1
        <span class="list-check"><i class="fa fa-check text-success" aria-hidden="true"></i></span>
    </li>

</ul>

1 个答案:

答案 0 :(得分:0)

错误是因为最愚蠢的原因(不知何故,Katalon没有告诉我):我试图访问列表的length; / *该成员在java.util.List中不存在! * / 我改为size()并且有效。

由于没有提醒我这件事,Katalon确实存在缺陷; / *他们说null没有被定义,但不是我试图访问一个不存在的成员* /