SELENIUM:如何检查HTML标签的特定属性中是否存在特定文本 [英] SELENIUM: how to check if a particular text is present in a particular attribute of HTML tag
问题描述
我有一个HTML标签:
< a href =rid = 7059> abc< / a>
< a href =pid = 8059> fgh< / a>
< a href =cid = 9059> cxq< / a>
HOw我检查 href
属性包含 rid
(上例中的第一个标签)
get_attribute ()
获取指定属性的值,但是如何检查页面中是否存在属性值 rid
? p>
感谢您的帮助。
你正在使用,所以从个人偏好我假设Python。其他语言不应该有什么不同。
is_element_present
函数可以用于此。从Selenium来源:
def is_element_present(self,locator):
验证指定的元素在页面上的某处
'locator'是一个元素定位器
return self.get_boolean(isElementPresent,[locator,]
对于定位器,您可以使用css = a [href * ='rid']
。
I have a HTML tags:
<a href="rid=7059"> abc </a>
<a href="pid=8059"> fgh </a>
<a href="cid=9059"> cxq </a>
HOw do I check if a particular tag exists with the href
attribute containing rid
(First tag in the above example)
get_attribute()
gets the value of a specified attribute but how do i check when in a page any such tag exists whose attribute value is rid
?
Thanks for the help.
You didn't mention the language you are using, so from personal preference I'm assuming Python. Other languages shouldn't really differ, though.
The is_element_present
function can be used for this. From the Selenium source:
def is_element_present(self,locator):
"""
Verifies that the specified element is somewhere on the page.
'locator' is an element locator
"""
return self.get_boolean("isElementPresent", [locator,]
For the locator you could use something along the lines of "css=a[href*='rid']"
.
这篇关于SELENIUM:如何检查HTML标签的特定属性中是否存在特定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!