Selenium: How to find element by partial href?

前端 未结 2 1951
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 16:01

Working code 1:

Driver.Instance.FindElement( By.XPath(\"//a[contains(@href,\'\" + PartialLinkHref + \"\')]\" ));

Working code 2:



        
2条回答
  •  無奈伤痛
    2021-02-15 16:28

    I don't think the problem is your selector, I think it's the object you're trying to return the results of FindElements to.

    In c#, FindElements returns a ReadOnlyCollection object, not a List object. If you change your linkList definition, it should work:

    ReadOnlyCollection linkList = Driver.Instance.FindElements(By.TagName("a"));
    

    You may also need to add this using:

    using System.Collections.ObjectModel;
    

提交回复
热议问题