RobotFramework中的复合类选择器与selenium

时间:2018-02-09 12:00:37

标签: css selenium robotframework

尝试检查从以下位置更改的元素的屏幕状态:

class="slide-out-div contrastBoxDark closed"

class="slide-out-div contrastBoxDark"

然而使用

Page Should Contain Element    class:slide-out-div.contrastBoxDark

返回

InvalidSelectorException: Message: invalid selector: Compound class names not permitted

如果不允许使用复合类名,那么这里有什么合适的定位器和属性?试过这个,但它找不到:

css:slide-out-div.contrastBoxDark

2 个答案:

答案 0 :(得分:2)

//your array containing the items. $aArray = array( array('Name' => 'Apple', 'Count' => 10), array('Name' => 'Tomato', 'Count' => 23), array('Name' => 'Tree', 'Count' => 4), array('Name' => 'Potato', 'Count' => 44), array('Name' => 'Apple', 'Count' => 73) ); //the character or string you want to search. $startWithChar = 'A'; //get all items of the array starting with the specified character or string. $newArray = array_filter($aArray, function($v) use ($startWithChar) { return strpos($v['Name'], $startWithChar) === 0; }); echo count($newArray); //2 搜索时,您不能使用多于1个班级名称。如果您想通过多于1个类名来查找元素,请尝试使用CSS selector:

对于"打开"

class

对于"关闭"

css:[class="slide-out-div contrastBoxDark"]
css:.slide-out-div.contrastBoxDark:not(.closed)

请注意,css:[class="slide-out-div contrastBoxDark closed"] 将匹配"已关闭"和"打开"元件...

另请注意,您的CSS选择器css:.slide-out-div.contrastBoxDark无法正常工作,因为它会忘记css:slide-out-div.contrastBoxDark之类的内容,因为您忘记了第一个类名称之前的点

答案 1 :(得分:2)

你在css选择器中的类slide-out-div之前缺少。(点)。请尝试以下方式,

css:.slide-out-div.contrastBoxDark