首页 > 解决方案 > css list-style-type decimal,编号自动化测试

问题描述

我有一个基于 js 和 css 的 pproject。我有一种情况,我将编号列表如下

  1. 咖啡
  2. 可乐

我正在通过

<!DOCTYPE html>
<html>
<head>
<style>
ul.a {list-style-type: decimal;}
</style>
</head>
<body>

<h1>The list-style-type Property</h1>

<p>Example of unordered lists:</p>

<ul class="a">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Cola</li>
</ul>

</body>
</html>

一切正常。但是现在的问题是,当我们通过自动化进行测试时,我们想检查列表是否有编号。但是由于列表是通过 css 控制的,所以它不会出现在 DOM 中。

有什么方法可以测试它。请帮忙

标签: htmlcssseleniumui-automation

解决方案


您可以使用getCssValue()selenium 中的方法来检索 css 属性。在你的情况下尝试

public boolean isListStyleTypeNumber() {

    return driver.findElement(By.cssSelector("ul.a")).getCssValue("list-style-type").equals("decimal") ? true : false;
}

推荐阅读