首页 > 解决方案 > 尝试通过 xlink:href 属性查找元素时出现 InvalidSelectorException

问题描述

我试图找到这样的元素:

<use xlink:href="site.org/path/action#edit"></use>

通过使用此选择器的给定属性:

  public static By ElementsSelector { get; set; } = By.CssSelector(@"use[xlink:href='site.org/path/action#edit']");

我通过以下方式找到元素:

 Driver.FindElements(EditProfilePage.ElementsSelector)[0].Click();

但我得到一个例外:

OpenQA.Selenium.InvalidSelectorException: 'invalid selector: An invalid or illegal selector was specified
  (Session info: chrome=78.0.3904.87)'

问题:如何找到具有给定xlink:href属性的元素?

标签: .netseleniumsvgxpathcss-selectors

解决方案


尝试不@使用 css 选择器:

public static By ElementsSelector { get; set; } = By.CssSelector("use[xlink:href='site.org/path/action#edit']");

推荐阅读