gpt4 book ai didi

selenium - 有没有办法在 Selenium Webdriver 或 Katalon Studio 中测试 Web 表的排序功能?

转载 作者:行者123 更新时间:2023-11-28 20:37:06 25 4
gpt4 key购买 nike

是否可以在 Katalon Studio/Selenium Webdriver 中测试 Web 表的排序功能?Katalon Studio/Selenium Webdriver 是否有任何默认方法来验证单个列中的数据是按升序还是降序排列?

以下是我用来获取 Web 表第一列中列出的所有值并将它们保存在数组中的代码:

WebDriver driver = DriverFactory.getWebDriver()

'To locate table'

WebElement Table = driver.findElement(By.xpath('/html[1]/body[1]/table[1]/tbody[1]'))



'To locate rows of table it will Capture all the rows available in the table'

List<WebElement> rows_table = Table.findElements(By.tagName('tr'))



'To calculate no of rows In table'

int rows_count = rows_table.size()



String[] celltext = new String[rows_count]

for (int row = 0; row < rows_count; row++) {

'To locate columns(cells) of that specific row'

List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName('td'))

'It will retrieve text from 1st cell'

String celltext_1 = Columns_row.get(0).getText()

celltext[row] = celltext_1

}

例如,celltext = [4,3,2,1]现在我想验证保存在 celltext 中的值是否按降序排列。

我们将不胜感激任何帮助。

最佳答案

selenium 和katalon 都不提供排序功能。但是您可以使用 java Arrays 实用程序类对项目进行排序并进行比较,如下所示。

String[] celltextBefore = celltext;

Arrays.sort(celltext, Collections.reverseOrder());

if(Arrays.equals(celltextBefore, celltext))
{
System.out.println("Celltext is in descending order");
}
else{
System.out.println("Celltext is not in descending order");
}

关于selenium - 有没有办法在 Selenium Webdriver 或 Katalon Studio 中测试 Web 表的排序功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50248157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com