Skip to main content

Selenium xpath wrapper to easily use in automation python

Project description

Xpath Wrapper


Selenium xpath wrapper framework
Selenium Xpath wrapper , support browsers Chrome, Firefox, Supported OS Windows, Linux, Ubuntu, Mac

Examples :

To Use Chrome Browser :

from xpathwrapper.basec import driver,checkbyxpath

driver.get('http://testing.pythonautomation.tk/')

checkbyxpath("//ul[@class='actions']//li/a[text()='Test Me']").click()

To Use Firefox Browser :

from xpathwrapper.basec import driver,checkbyxpath

driver.get('http://testing.pythonautomation.tk/')

checkbyxpath("//ul[@class='actions']//li/a[text()='Test Me']").click()

.................................... Key Words ..........................

checkbyid(locator):

"""
checkbyid(locator)

Locating by Id; Use this when you know id attribute of an element. With this strategy, 
the first element with the id attribute value matching the location will be returned.
If no element has a matching id attribute, a NoSuchElementException will be raised..

checkbyid('loginForm')

"""
driver.find_element_by_id(locator)

checkbyname(locator):

"""
checkbyname(locator)

Locating by Name; Use this when you know name attribute of an element. With this strategy,
 the first element with the name attribute value matching the location will be returned. 
 If no element has a matching name attribute, a NoSuchElementException will be raised. 

checkbyname('username')

"""
driver.find_element_by_name(locator)

checkbyxpath(locator):

"""
checkbyxpath(locator)

Locating by XPath; XPath is the language used for locating nodes in an XML document. As HTML can 
be an implementation of XML (XHTML), Selenium users can leverage this powerful language to target 
elements in their web applications. XPath extends beyond (as well as supporting) the simple methods 
of locating by id or name attributes, and opens up all sorts of new possibilities such as locating 
the third checkbox on the page.

One of the main reasons for using XPath is when you don't have a suitable id or name attribute for 
the element you wish to locate. You can use XPath to either locate the element in absolute terms 
(not advised), or relative to an element that does have an id or name attribute. XPath locators can 
also be used to specify elements via attributes other than id and name.

Absolute XPaths contain the location of all elements from the root (html) and as a result are likely 
to fail with only the slightest adjustment to the application. By finding a nearby element with an id 
or name attribute (ideally a parent element) you can locate your target element based on the 
relationship. This is much less likely to change and can make your tests more robust. 

checkbyxpath('/html/body/form[1]')

"""
driver.find_element_by_xpath(locator)

checkbylinktext(locator):

"""
checkbylinktext(locator)

Locating Hyperlinks by Link Text; Use this when you know link text used within an anchor tag. 
With this strategy, the first element with the link text value matching the location will be 
returned. If no element has a matching link text attribute, a NoSuchElementException will be raised.

checkbylinktext('Continue')

"""
driver.find_element_by_link_text(locator)

checkbypartialtext(locator):

"""
checkbypartialtext(locator)

findFileByName; Search the file by using name of the file in directory.
Once using name indicates the file name and path indicates the directory where
you want to search. 

checkbypartialtext('Conti')

"""
driver.find_element_by_partial_link_text(locator)

checkbytag(locator):

"""
checkbytag(locator)

Locating Elements by Tag Name; Use this when you want to locate an element by tag name. 
With this strategy, the first element with the given tag name will be returned. If no 
element has a matching tag name, a NoSuchElementException will be raised.

checkbytag('h1')

"""
driver.find_element_by_tag_name(locator)

checkbyclass(locator):

"""
checkbyclass(locator)

Locating Elements by Class Name; Use this when you want to locate an element by class 
attribute name. With this strategy, the first element with the matching class attribute 
name will be returned. If no element has a matching class attribute name, a 
NoSuchElementException will be raised. 

checkbyclass('content')

"""
driver.find_element_by_class_name(locator)

checkbycss(locator):

"""
checkbycss(locator)

Locating Elements by CSS Selectors; Use this when you want to locate an element by CSS selector
syntax. With this strategy, the first element with the matching CSS selector will be returned.
If no element has a matching CSS selector, a NoSuchElementException will be raised. 

checkbycss('p.content')

"""
driver.find_element_by_css_selector(locator)

checkbynames(locator):

"""
checkbynames(locator)

Locating by Name; Use this when you know name attribute of an element. With this strategy,
the first element with the name attribute value matching the location will be returned. 
If no element has a matching name attribute, a NoSuchElementException will be raised. 

checkbynames('username')

"""
driver.find_elements_by_name(locator)

checkxpathelements(locator):

"""
checkxpathelements(locator)

Locating by XPath; XPath is the language used for locating nodes in an XML document. As HTML can 
be an implementation of XML (XHTML), Selenium users can leverage this powerful language to target 
elements in their web applications. XPath extends beyond (as well as supporting) the simple methods 
of locating by id or name attributes, and opens up all sorts of new possibilities such as locating 
the third checkbox on the page.

One of the main reasons for using XPath is when you don't have a suitable id or name attribute for 
the element you wish to locate. You can use XPath to either locate the element in absolute terms 
(not advised), or relative to an element that does have an id or name attribute. XPath locators can 
also be used to specify elements via attributes other than id and name.

Absolute XPaths contain the location of all elements from the root (html) and as a result are likely 
to fail with only the slightest adjustment to the application. By finding a nearby element with an id 
or name attribute (ideally a parent element) you can locate your target element based on the 
relationship. This is much less likely to change and can make your tests more robust. 

checkxpathelements('/html/body/form[1]')

"""
driver.find_elements_by_xpath(locator)

checkbylinktexts(locator):

"""
checkbylinktexts(locator)

Locating Hyperlinks by Link Text; Use this when you know link text used within an anchor tag. 
With this strategy, the first element with the link text value matching the location will be 
returned. If no element has a matching link text attribute, a NoSuchElementException will be raised.

checkbylinktexts('Continue')

"""
driver.find_elements_by_link_text(locator)

checkbypartialtexts(locator):

"""
checkbypartialtexts(locator)

findFileByName; Search the file by using name of the file in directory.
Once using name indicates the file name and path indicates the directory where
you want to search. 

checkbypartialtexts('Conti')

"""
driver.find_elements_by_partial_link_text(locator)

checkbytagelements(locator):

"""
checkbytagelements(locator)

Locating Elements by Tag Name; Use this when you want to locate an element by tag name. 
With this strategy, the first element with the given tag name will be returned. If no 
element has a matching tag name, a NoSuchElementException will be raised.

checkbytagelements('h1')

"""
driver.find_elements_by_tag_name(locator)

checkbyclassnames(locator):

"""
checkbyclassnames(locator)

Locating Elements by Class Name; Use this when you want to locate an element by class 
attribute name. With this strategy, the first element with the matching class attribute 
name will be returned. If no element has a matching class attribute name, a 
NoSuchElementException will be raised. 

checkbyclassnames('content')

"""
driver.find_elements_by_class_name(locator)

checkbycssselectors(locator):

"""
checkbycssselectors(locator)

Locating Elements by CSS Selectors; Use this when you want to locate an element by CSS selector
syntax. With this strategy, the first element with the matching CSS selector will be returned.
If no element has a matching CSS selector, a NoSuchElementException will be raised. 

checkbycssselectors('p.content')

"""
driver.find_elements_by_css_selector(locator)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xpathwrapper-1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xpathwrapper-1.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file xpathwrapper-1.1.tar.gz.

File metadata

  • Download URL: xpathwrapper-1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

File hashes

Hashes for xpathwrapper-1.1.tar.gz
Algorithm Hash digest
SHA256 7e58f24197ac810a49a5da34f383d0c7d7eb40fa1866c48348ac50fcce3fe3dc
MD5 06f23f4e478ca6f3ca83230a92480d01
BLAKE2b-256 f58ac4beaf6d4988fe397e6cdf9a51661625391eb74b0f036e7b78c6e6318a4c

See more details on using hashes here.

File details

Details for the file xpathwrapper-1.1-py3-none-any.whl.

File metadata

  • Download URL: xpathwrapper-1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

File hashes

Hashes for xpathwrapper-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e251382da2d712cecb71b20092df75b5522a901df348012522102a98fe1cbf7
MD5 f9c216f7486a8fe58caaf28cc733263e
BLAKE2b-256 9ee56faf75836a393c890805f01c5a178cb9e9c2067e05c8cfa61f56a49f7b88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page