title: Why does a function in nested XPATH conditional cause the error?
body: <p>This is a question about an "xpath expression is invalid" error received from a webDrv.find_elements_by_xpath() call.</p>
  
  <p><strong>Background</strong></p>
  
  <p>While searching a jobs website for elements containing target job title text, e.g., "scrum master" (normalized to lower()), found in an element such as</p>
  
  <pre><code>&lt;a href="/jobs/view/1836192833/"&gt;
      Scrum MASTER
  &lt;/a&gt;
  </code></pre>
  
  <p>the Selenium-Python query...</p>
  
  <p><code>aJobTitle = getNormalJobTitle(...)  # to match "scrum master" with "Scrum Master" "SCRUM Master" etcA
  s = '// *[contains(translate(text(),"ABCDEFGHIJKLMNOPURSTUWXYZ", "abcdefghijklmnopurstuwxyz"), "' + aJobTitle + '")]'
  jobNodes = webDrv.find_elements_by_xpath(s)</code></p>
  
  <p>works perfectly. All "Scrum MASTER," "Scrum Master," Scrum master," etc. elements returned.</p>
  
  <p>However, when a website -- for whatever reasons -- includes other elements, e.g., </p>
  
  <p><code>&lt;a href="/jobs/view/1836192833/"&gt; Scrum Master &lt;!----&gt; &lt;/a&gt;</code></p>
  
  <p>the query above finds nothing.</p>
  
  <p>Using a different xpath form -- and working without the lower() normalization...</p>
  
  <p><code>s = "//*[text()[contains(.,'" + "Scrum MASTER" + "')]]"
  jobNodes = webDrv.find_elements_by_xpath(s)</code></p>
  
  <p>works perfectly.  All, and only, "Scrum MASTER" elements returned (but not "Scrum Master," etc., of course)</p>
  
  <p><strong>My Problem</strong></p>
  
  <p>However, when I try to search using a normalized job title in lowercase by substituting the call to <code>text()</code> with a call to <code>translate(text(),,)</code>... </p>
  
  <p><code>aJobTitle = getNormalJobTitle(...) # "scrum master"
  s = "//*[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')[contains(.,'" + aJobTitle + "')]]"</code></p>
  
  <p>I'm treated to</p>
  
  <p><code>Exception has occurred: InvalidSelectorException
  Message: Given xpath expression "//*[translate(tex(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')[contains(.,'scrum master')]]" is invalid:
  [Exception... "&lt;no message&gt;"  nsresult: "0x80600008 (&lt;unknown&gt;)"  location: "JS frame :: chrome://marionette/content/element.js :: element.findByXPathAll :: line 410"  data: no]
    File "C:myfile.py JS.py", line 41, in &lt;module&gt;
      jn = liJobsElement.find_elements_by_xpath(s)</code></p>
  
  <p>So finally...</p>
  
  <p>1) Why does the addition of a function cause the error?<br />2) How might I achieve the normalization such that I can find all case forms of, e.g., a job title?</p>