user1303594
user1303594

Reputation: 103

Checking IDs with Selenium & Python

I am running a selenium test with python. I am having a specific problem with the following bit of html code.....

<span class="cke_label" id="cke_8_label">Source</span>

I have tried the following.......

self.assert_element_present_by_class('Source button', 'cke_8_label', 'cke_label')**

here's the function .........

def assert_element_present_by_class(self, description, id, name):
    sel = self.selenium
    try:
        self.assert_(sel.is_element_present("//" + id + "[contains(@class,'" + name + "')]"))
        logging.info('PASS: "' + description + '" is present')
    except Exception:
        logging.exception('FAIL: "' + description + '" is not present')

This gives me this error.......

File "Template_Designer_P37.py", line 293, in assert_element_present_by_class self.assert_(sel.is_element_present("//" + id + "[contains(@class,'" + name + "')]")) File "C:\Python27\lib\unittest\case.py", line 420, in assertTrue raise self.failureException(msg) AssertionError: False is not true

I have tried a couple of other methods, such as simply trying to assert that the id *strong text*exists

My hunch is that the problem surrounds the 'id'

Any thoughts?

Upvotes: 0

Views: 181

Answers (1)

Aleh Douhi
Aleh Douhi

Reputation: 1978

You try to use incorrect xpath and insert id instead of tag name. So correct version will be

self.assert_(sel.is_element_present("//*[@id='" + id + "' and contains(@class,'" + name + "')]"))

Upvotes: 2

Related Questions