如何避免页面对象中的复合类名称错误? [英] How to avoid Compound Class name error in Page Object?

查看:17
本文介绍了如何避免页面对象中的复合类名称错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在页面对象中使用具有空格 class = "country name" 的类名时,我得到:

When I try to use the class name that having space class = "country name" in page object, I'm getting:

Compound class names not permitted Selenium::WebDriver::Error::UnknownError)

如何使用有空格的类名.

How can I use the class name that having space.

例如:

class = "country name"

推荐答案

改用 CSS 选择器:

Use a CSS selector instead:

.country.name

需要注意的重要一点是这个例子是错误的!如果 "country name" 是一个国家的名字,那就是.类名中不能有空格.事实上,class 属性是一个以空格分隔的类列表.这意味着如果你有一个 country name 类,它不是一个类,它是你的元素所属的两个不同的类 - 第一个是 country,第二个是name

The important thing to note is that this example is wrong! If "country name" is meant as a name of a country, that is. Class names can't have spaces in them. In fact, the class attribute is a space-separated list of classes. That means that if you have a class country name, it's not one class, it's two different classes your element belongs to - the first is country, the second is name!

因此,如果您的课程有误,请修正它们.如果不是,请使用 CSS 选择器,这是匹配多个类的唯一可靠方法(除了非常长且复杂的 XPath 表达式).不要使用简单的 XPath 表达式或 CSS 选择器进行简单的属性比较(//*[@class='country name']*[class='country name']>),这是完全错误的.

Therefore, fix your classes, if they're wrong. If they're not, use a CSS selector, it's the only reliable way to match multiple classes (apart from a very long and complicated XPath expression). Don't use trivial XPath expressions or CSS selectors with naive attribute comparison (//*[@class='country name'] or *[class='country name']), that's just plain wrong.

这篇关于如何避免页面对象中的复合类名称错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆