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 Answer 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– DEnumber502015年06月03日 22:09:48 +00:00Commented 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.Niels van Reijmersdal– Niels van Reijmersdal2015年06月04日 07:12:33 +00:00Commented Jun 4, 2015 at 7:12
-
Fixing the syntax error fixed my issue.DEnumber50– DEnumber502015年06月04日 14:18:03 +00:00Commented Jun 4, 2015 at 14:18