Skip to content

Instantly share code, notes, and snippets.

@VladSem
Last active October 1, 2015 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VladSem/d08bcfd3b894d506b752 to your computer and use it in GitHub Desktop.
Save VladSem/d08bcfd3b894d506b752 to your computer and use it in GitHub Desktop.
how to find text between two specific characters in Firefox XPath and Python
# Firefox XPath
# Full XPath = html/body/div[5]/form/table/tbody/tr/td[2]/table/tbody/tr/td/div/span[4]
# Result: SWI9X15C_05.05.16.02 r21040 carmd-fwbuild1 2014/03/17 23:49:48
# XPath: substring-before(substring-after(//span[4], 'C_'), ' r')
# Result: 05.05.16.02
# Python Selenium/Webdriver
get_firmware_version = browser.find_element_by_xpath("//span[4]").text
# Result: get_firmware_version = SWI9X15C_05.05.16.02 r21040 carmd-fwbuild1 2014/03/17 23:49:48
a = 'C_'
b = ' r'
firmware = get_firmware_version.split(a)[1].split(b)[0]
print firmware # 05.05.16.02
firmware2 = get_firmware_version[get_firmware_version.find('C_')+2:get_firmware_version.find(' r')]
print firmware # 05.05.16.02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment