Can some one help me to find the CSS selector for highlighted item



  • Could someone help me to identify the correct csslocator for the second span element in the below image:

    enter image description here

    I tried the below locators but was not able to succeed, is there anything wrong with the locator used ?

    driver.FindElement(By.CssSelector("class[onclick='gotoReportView(20, 'ReportSectionc5404625cccfdb7d5563')']")).Click();
    
    driver.FindElement(By.CssSelector("Span[onclick='gotoReportView(20, 'ReportSectionc5404625cccfdb7d5563')']")).Click();
    


  • I would like to suggest a different way to get to the element that I use a lot. It might be slower, because it does mutliple FindElement(s) calls, but it is so much more readable and understandable.

    var container = driver.FindElement(By.ClassName("items-container"));
    var spans = container.FindElements(By.TagName("span"))
    spans[1].Click();
    

    You find the div and then search for elements within the div and then take the second one to interact with.



Suggested Topics