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.

asked Jun 3, 2015 at 21:07

1 Answer 1

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.