是否可以使用 Selenium2Library 关键字找到父元素及其子元素?

Is it possible to find a parent element and its child element using Selenium2Library Keywords?

我最近从 python + selenium 切换到了 Robot Framework。在 python + selenium 中,我们可以:

parent = webdriver.find_element_by_css_seletor("parentCssSelector")
child = parent.find_element_by_css_selector("childCssSelector")

就我个人而言,我非常喜欢这种方法,因为它允许以 "fine" 的方式定位元素。但是用了几天Robot framework + selenium2library,还没找到实现的方法。请问有谁知道用Robot framework + selenium2library怎么做吗?

谢谢

定位或指定元素

Selenium2Library 中所有需要在页面上查找元素的关键字都有一个参数,可以是定位器,也可以是现在的网络元素。 locator 是一个字符串,描述如何使用指定不同定位策略的语法来定位元素。 webelement 是一个包含 WebElement 实例的变量,它是元素的表示。

使用'locator'

默认情况下,当提供定位符值时,它会与特定元素类型的关键属性相匹配。例如,id 和 name 是所有元素的关键属性,仅使用 id 作为定位器定位元素很容易。

例如: 单击元素 my_element

还可以通过指定带有定位器前缀的查找策略来指定 Selenium2Library 应该采用的查找元素的方法。支持的策略是:

使用 CSS 作为定位器

css 单击元素 | css=div.my_class 按 CSS 选择器

匹配

更多不同的定位器示例请参考

http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html