如何避免Page Object中的Composite Class name错误? [英] How to avoid Compound Class name error in Page Object?

查看:76
本文介绍了如何避免Page Object中的Composite Class name错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用在页面对象中具有空格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选择器:

.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.

这篇关于如何避免Page Object中的Composite Class name错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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