简体   繁体   English

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

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

I have recently switched to Robot Framework from python + selenium. 我最近从python + selenium切换到了Robot Framework。 In python + selenium, we could: 在python +硒中,我们可以:

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

Personally, I really like this approach as it allows a "fine" way to locate an element. 就个人而言,我真的很喜欢这种方法,因为它允许“精细”的方式来定位元素。 But after a few days of using Robot framework + selenium2library, I have not discovered a way to achieve this. 但是,在使用Robot框架+ selenium2library几天后,我还没有发现实现此目的的方法。 May I ask if anyone knows how to do this using Robot framework + selenium2library? 请问是否有人知道如何使用Robot Framework + selenium2library?

Thanks 谢谢

Locating or specifying elements 定位或指定元素

All keywords in Selenium2Library that need to find an element on the page take an argument, either a locator or now a webelement. Selenium2Library中需要在页面上查找元素的所有关键字都带有一个参数,即定位符或现在的webelement。 locator is a string that describes how to locate an element using a syntax specifying different location strategies. locator是一个字符串,它描述如何使用指定不同定位策略的语法来定位元素。 webelement is a variable that holds a WebElement instance, which is a representation of the element. webelement是一个变量,其中包含一个WebElement实例,该实例是元素的表示形式。

Using 'locator' 使用“定位器”

By default, when a locator value is provided, it is matched against the key attributes of the particular element type. 默认情况下,当提供定位符值时,它将与特定元素类型的键属性匹配。 For example, id and name are key attributes to all elements, and locating elements is easy using just the id as a locator. 例如,id和name是所有元素的关键属性,仅使用id作为定位符就可以轻松定位元素。

For example: Click Element my_element 例如:单击元素my_element

It is also possible to specify the approach Selenium2Library should take to find an element by specifying a lookup strategy with a locator prefix. 通过指定带有定位符前缀的查找策略,也可以指定Selenium2Library查找元素所采用的方法。 Supported strategies are: 支持的策略是:

Using CSS as locator 使用CSS作为定位器

css Click Element | css单击元素| css=div.my_class Matches by CSS selector css = div.my_class通过CSS选择器进行匹配

For more different locator examples please refer 有关更多不同的定位器示例,请参阅

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM