Finding elements

For finding elements you can use five methods, one for each selector type css, xpath, tag, name, id:

browser.find_by_css('h1')
browser.find_by_xpath('//h1')
browser.find_by_tag('h1')
browser.find_by_name('name')
browser.find_by_id('firstheader')

These methods returns a list of all found elements.

you can get the first found element:

browser.find_by_name('name').first

You can use too the last attribute, that returns the last found element:

browser.find_by_name('name').last

Get element using index

You also use index for get a element

browser.find_by_name('name')[1]

all elements and find_by_id

A web page should be only one id per page. Then find_by_id() method return always a list with one element.

Element not found exception

If element not found, find methods returns a empty list. But, if you try, access a element in list raises the splinter.element_list.ElementDoesNotExist exception.

Table Of Contents

This Page