0

I have an element onscreen that I am attempting to click, my test runner is telling me that SyntaxError: The expression is not a legal expression. I am trying to access an ' i ' tag on a button.

Here is my call to the driver:

driver.FindElement(By.XPath("//i[contains(@class, 'icon-magnifier']")).Click();

Here is my HTML

<button type="submit">
    <i class="icon-magnifier"></i>
</button>

I would use the cssselector as my reference but when cut and paste from firebug it is ridiculously lengthy. Let me know what you would suggest to access this element.

1

You are missing a ) in there: "//i[contains(@class, 'icon-magnifier')]"

I think the cssselector would look like: By.cssSelector(".icon-magnifier") unless you have multiple icon-magnifier's it should find this one.

  • That worked great, can you answer to why I cannot reference an <i> tag like above? seems to work with any other HTML tag. – DEnumber50 Jun 3 '15 at 22:09
  • You mean reference By.Xpath? I think it should work, but you had an syntax error in the Xpath. – Niels van Reijmersdal Jun 4 '15 at 7:12
  • Fixing the syntax error fixed my issue. – DEnumber50 Jun 4 '15 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.