问题
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.
回答1:
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']"
.
回答2:
When locating the element, use XPath expression like //a[contains(@href,'rid')]
, so isElementPresent(//a[contains(@href,'rid')])
should do.
来源:https://stackoverflow.com/questions/7804722/selenium-how-to-check-if-a-particular-text-is-present-in-a-particular-attribute