title: C# selenium webdriver css selector for label with only text Sign Out
body: <p>I was not able to get satisfactory answer after searching on google.
  So could you please guide me on this?
  I have a div containing li,a,labels below it.
  I am able to find the div using CssSelector by its class name.
  Now inside this div I want to get a label with its text and then click on it.
  The label is as belo:</p>
  
  <p>&lt;label&gt;Sign Out&lt;/label&gt;</p>
  
  <p>How to do that ?</p>
  
  <p>I have a working solution using XPath and iterating over all labels inside div, but I am unable to get it using CssSelector.</p>
  
  <p>My Solution:</p>
  
  <pre><code>IWebElement menu = CurrentDriver.FindElement(By.CssSelector("div[class='menu-panel right']"));
  IWebElement logoutLabel = menu.FindElement(By.XPath("//label[text()='Sign Out']"));
  </code></pre>
  
  <p>or
  by using foreach:</p>
  
  <pre><code>var coll = menu.FindElements(By.TagName("label"));
  foreach (var label in coll)
  {
    if(label.Text.Trim() =="Sign Out")
    {
        Log("Sign out was found.");
        label.Click();
        break;
    }
  }
  </code></pre>
  
  <p>I tried with CssSelector:</p>
  
  <pre><code>IWebElement logoutLabel = menu.FindElement(By.CssSelector(":contains('Sign Out')"));
  IWebElement logoutLabel = menu.FindElement(By.CssSelector("label:contains('Sign Out')"));
  IWebElement logoutLabel = menu.FindElement(By.CssSelector("label['Sign Out']"));
  </code></pre>
  
  <p>But these are not working.</p>