Page.get_element#

Page.get_element(element_id, do_copy=False)[source]#

Gets an element from its id attribute. You can imagine this function as document.getElementById in JavaScript.

Creating a page and getting an element by its id:

>>> page = Page(html_str='<html><h1 id="heading">Hello</h1></html>', url="/")
>>> element = page.get_element(element_id="heading")
>>> element
<h1 id="heading">Hello</h1>
Parameters:
  • element_id (str) –

  • do_copy (bool, default = False) – If True, the element will be copied.

Returns:

element – If the element was found, an Element object will be returned. Otherwise None will be returned.

Return type:

Element