find_element_by_tag_name和find_elements_by_tag_name有什么区别? [英] What is the difference between find_element_by_tag_name and find_elements_by_tag_name?
问题描述
单数名称的函数和复数名称的函数有什么区别?
What is the difference between the function with the singular name and the one with the plural name?
find_element_by_name
find_elements_by_name
和
find_element_by_tag_name
find_elements_by_tag_name
推荐答案
我对python和selenium并不很熟悉,但是大多数DOM函数的行为都相同.
I'm not all that familiar with python and selenium but most DOM functions act the same way.
find_element_by_name
应该返回其name属性与名称相匹配的元素(找到的第一个实例)
find_element_by_name
should return an element who's name attribute matches the name (the first instance found)
<input name="username" type="text" value="Enter Username" />
find_elements_by_name
将返回匹配元素的集合/数组
find_elements_by_name
will return a collection/array of matching elements
<input name="continue" type="submit" value="Login" />
<input name="continue" type="button" value="Clear" />
find_element_by_tag_name
与之类似,只是返回具有匹配标签名称的元素的第一个实例.
find_element_by_tag_name
will be similar only returning the first instance of an element with the matching tag name.
find_element_by_tag_name("a") // return the first anchor
find_elements_by_tag_name
将再次返回匹配标签名称的集合/数组.
find_elements_by_tag_name
will again return a collection/array of matching tag names.
如果可以链接这些命令或在存储的元素上调用它们,则get_element(s)_*
函数的结果将与其调用的节点有关.
If its possible to chain these commands, or call them on stored elements the result from get_element(s)_*
functions will be relative to node its called on.
<html>
<body>
<div>
<a href="#1">Example 1</a>
<a href="#2">Example 2</a>
</div>
<span>
<a href="#3">Example 3</a>
<a href="#4">Example 4</a>
</span>
</body>
</html>
示例
find_element_by_tag_name("a")
== Example 1
find_element_by_tag_name("span").find_element_by_tag_name("a")
== Example 3
在集合/数组上迭代
links = browser.find_elements_by_tag_name("a")
for link in links
# link should be a Selenium WebElement?
如有疑问,您可以转储整个结果以查看结果.
if in doubt you can just dump the whole result to see what is in it.
这篇关于find_element_by_tag_name和find_elements_by_tag_name有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!