browser_driver package¶
browser_driver is a wrapper for selenium components to manipulate testing with a browser. We purposely wrap the native functionality to protect from version issues. It is not uncommon for a browser to make a change which breaks automation. We have found we can make easier updates to accommodate, if our calls go through a central method. For instance one change to the browser caused links which were previously found when out of view, to stop being found. You thus needed to scroll it into view and then find it. This wrapper provides ability for that.
Submodules¶
browser_driver.browser module¶
browser is the primary class for this Python package. An instance of this class will wrap a browser driver for IE, Edge, Chrome, Firefox, Phantom or other configured Selenium drivers. This wrapper class allows us to insulate browser changes. If a browser does something to change the behavior of selenium, we can add code here to deal with it. For instance a browser change once required us to scroll objects in to view to find them, where prior to the change it did not.
-
class
browser_driver.browser.
WebBrowser
(browser=None, logger=None)[source]¶ Bases:
object
-
browser_factory
(browser)[source]¶ This method will return a selenium driver object to manipulate the browser. The method can provide a pseudo random creation of standard, visible, browsers.
-
check_by_id
(element_id)[source]¶ Checks a checkbox, finding it by an html id value. If not selected will click() the box. Otherwise will leave the state unchanged. This method does NOT toggle state of the checkbox.
-
check_by_xpath
(xpath)[source]¶ Checks a checkbox, finding it by an xpath statement. If not selected will click() the box. Otherwise will leave the state unchanged. This method does NOT toggle state of the checkbox.
-
click_element
(locate_by, locator)[source]¶ This method will wait for an element to become present, and for the element to become clickable before trying to click. Useful in situations where an element may be loaded in with AJAX, or has an animation
-
click_to_new_page
(**kwds)[source]¶ This is a wrapper for clicking an HTML hyperlink. This method is specific to clicking a non-javascript link that loads a new page. The method adds functionality to wait for the new page to load before retruning. this addresses a common challenge.
Thanks to http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html
-
click_to_new_page_by_id
(html_id)[source]¶ This method finds an element by id, clicks it, and waits for the new page to load before returning.
-
find_element
(locator)[source]¶ Wrapper for finding an element using the wait technique. This should help make the retrieval of the element more compatible with AJAX style web design. Using locator syntax to access locator[] and the By and Value portions in logging an error.
-
find_element_by_class_name
(class_name)[source]¶ Returns a selenium element class for the object found by class name. Wrapper for selenium method. Calls a class method, which in turn, calls the Selenium base method, and handles errors, logging, etc.
-
find_element_clickable
(locator)[source]¶ Wrapper for finding if an element is clickable using the wait technique.
-
find_elements
(locator)[source]¶ Wrapper for finding an element using the wait technique. This should help make the retrieval of the element more compatible with AJAX style web design. Using locator syntax to access locator[] and the By and Value portions in logging an error.
- TODO:
- Create tests for the elements wrappers
-
find_elements_by_class_name
(class_name)[source]¶ Returns a list of elements matching the class name.
-
find_elements_by_css_selector
(css_selector)[source]¶ Returns a list of elements matching the css selector.
-
find_elements_by_link_text
(html_a_tag_text)[source]¶ Returns a list of elements where the link, has text (seen by reader), with the exact text passed to method.
-
find_elements_by_name
(html_tag_name)[source]¶ Returns a list of elements matching the html tag pattern name=value.
-
find_elements_by_partial_link_text
(html_a_tag_text)[source]¶ Returns a list of elements where the link, has text (seen by reader), containing text passed to method.
-
find_elements_by_tag_name
(tag_name)[source]¶ Returns a list of elements where the tag name matches the text passed to method.
-
find_elements_by_xpath
(xpath_search)[source]¶ Returns a list of elements matching the xpath search pattern.
-
host
¶
-
ip_port
¶
-
name
¶ This is a wrapper method for the native Selenium functionality. While a user could all WebBrowser.driver.name this design allows for code to be done in a uniform way across all tests code, and it is more intuitive than having to know this object contains another object called driver.
-
quit
()[source]¶ This is a wrapper method for the native Selenium functionality. While a user could all WebBrowser.driver.quit() this design allows for additional code to be done in a uniform way across all tests code, and it is more intuitive than having to know this object contains another object called driver.
-
send_keys
(element, keys_to_type)[source]¶ When passed an element found to be clickable, will calls the send keys method to type the passed string in the textbox.
-
uncheck_by_id
(element_id)[source]¶ Removes check on a checkbox, finding it by an html id. If selected will click() the box to deselect. Otherwise will leave the state unchanged. This method does NOT toggle state of the checkbox.
-
uncheck_by_xpath
(xpath)[source]¶ Removes check on a checkbox, finding it by an xpath statement. If selected will click() the box to deselect. Otherwise will leave the state unchanged. This method does NOT toggle state of the checkbox.
-
url
¶ Return the current url in the browser.
-