GUI Elements Locators Flashcards
find_element_ (return a single WebElement) or find_elements_ (return a list of WebElements) methods:
by_id (id_) by_class_name (name) by_tag_name (name) by_xpath (xpath) by_css_selector (css_selector)
W3C DOM Definition
A platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.
What it is included in the DOM definition of web elements?
- HTML elements as objects
- The properties of all HTML elements
- The methods that can be used to access all HTML elements
- The events that affect all HTML elements
CODE: Locate by ID
element = driver.find_element_by_id(‘the_id’)
CODE: Locate by Class
element = driver.find_element_by_class_name(‘the_class’)
CODE: Locate by Tag
element = driver.find_element_by_tag_name(‘h2’)
Two methods to identify the WebElement by the link text (an anchor tag which contains text that will be highlighted for a user to click on):
element = driver.find_element_by_link_text(‘Click the link’)
element = driver.find_element_by_partial_link_text(‘Click’)
CODE: Using XPath Location
element = driver.find_element_by_xpath(‘//form[@id=’sample’]/input[2]’)
CODE: Identifying WebElement via CSS Selector
driver.find_element_by_css_selector(‘p.paragraph’)
predefined classes that do not simply determine if an element exists, but also check for a specific state for that element to be in.
expected_conditions module from selenium.webdriver.support
For test automation, what are the reasons do we have to know more information (its current visibility, whether it is enabled or not, or whether it is selected or not) about the elements in a webpage?
- Ensure the state is as expected at a given point in the test
- Make sure a control is in a state that it can be manipulated as needed in the test case (i.e., enabled)
- Make sure that after the control was manipulated, it is now in the expected state
- Make sure that the expected results are correct after a test is run
get_attribute()
Gets property. If no property by that name, gets attribute of that name. If neither, returns None
get_property()
Gets property.
is_displayed()
Returns true if visible to user
is_enabled()
returns true if element is enabled