There is a code with the following script:

  1. Search links on the page
  2. If the text contains a "C # program" , then the code clicks on the link.
private void button4_Click(object sender, EventArgs e) { List<IWebElement> Element = Browser.FindElements(By.CssSelector("#tabnews_newsc a")).ToList(); for (int i = 0; i < Element.Count; i++ ) { String s = Element[i].Text; if (s.Contains("программа на C#")) // если текст СОДЕРЖИТ { Element[i].Click(); // КЛИК по новости, которая СОДЕРЖИТ искомый текст break; } } } 

Question:

How to make a search be performed case insensitive to search text?

Those. if the text contains "C # program", then the transition is carried out, and if the text contains "C # program" (the word "Program" with a capital "P"), then the link does not occur.

    2 answers 2

     if (s.ToLower().Contains("программа на c#")) 

    So it is possible

      This code should work as you need:

       var link= Browser.FindElement(By.Xpath(".//a[contains(text(),'программа на C#')]")); if (link!= null) link.Click(); 

      and remove all your code :)