1
votes

I am fairly new to Selenium for C#. I want to click on the element between the <svg> tag (image below). I have tried the following :

 driver.FindElement(By.XPath("//use[@href='#events-widget']")).Click();
 driver.FindElement(By.XPath("//use[@href='#events-widget'/]")).Click();
 driver.FindElement(By.XPath("//use[@xlink:href='#events-widget']")).Click();
 driver.FindElement(By.XPath("//use[@xlink:href='#events-widget']/")).Click();
 driver.FindElement(By.LinkText("Events")).Click();

enter image description here

Help would be appreciated :)

1
Is the FindElement returning an IWebElement?Mike Weber
Yes it returns an IWebElementShashank
Sometimes you got to click twice because the first time only focus the control. In other words, you have to repeat the line twice.Fjodr
@Fjodr Hi ! I will try that :). But are any of these calls correct ?Shashank
you can test the xpath in the console of the browser's developer tools by entering $x("//use[@href='#events-widget']")Mike Weber

1 Answers

0
votes

I'm not using Selenium from C#, but from Nightwatchjs. We're using <svg> for icons and I select the <use xlink:href="/svg-icons/sprite.stack.svg#sort-ascending"></use> element with this css selector:

'use[*|href="/svg-icons/sprite.stack.svg#sort-ascending"]'

I would guess this also works from C#.