SELENIUM:如何检查HTML标签的特定属性中是否存在特定文本 [英] SELENIUM: how to check if a particular text is present in a particular attribute of HTML tag

查看:270
本文介绍了SELENIUM:如何检查HTML标签的特定属性中是否存在特定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆