我正在尝试在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>
答案 0 :(得分:0)
错误是因为最愚蠢的原因(不知何故,Katalon没有告诉我):我试图访问列表的length
; / *该成员在java.util.List
中不存在! * /
我改为size()
并且有效。
null
没有被定义,但不是我试图访问一个不存在的成员* /