Sunny
Sunny

Reputation: 7604

SELENIUM: how to check if a particular text is present in a particular attribute of HTML tag

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.

Upvotes: 0

Views: 1758

Answers (2)

jro
jro

Reputation: 9474

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']".

Upvotes: 1

Harri
Harri

Reputation: 2732

When locating the element, use XPath expression like //a[contains(@href,'rid')], so isElementPresent(//a[contains(@href,'rid')]) should do.

Upvotes: 2

Related Questions