Skip to content

Instantly share code, notes, and snippets.

@brizandrew
Created August 5, 2016 19:44
Show Gist options
  • Save brizandrew/0059df27ce9ca3ac5287d913c64cf801 to your computer and use it in GitHub Desktop.
Save brizandrew/0059df27ce9ca3ac5287d913c64cf801 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
"""
@function elementExists
Checks if a given element exists on the driver page given a search type and value
@param {WebDriver} driver: The driver to search for
@param {str} locateType: The type of search to preform (only "by_id" is supported)
@param {str} locateValue: The value of a given type to search for (only "id" is supported)
@return {boolean}: Whether or not it exists
"""
def elementExists(driver, locateType, locateValue):
try:
if locateType == 'id':
driver.find_element_by_id(locateValue)
return True
except NoSuchElementException:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment