How can I select a link text using a css selector?

css-selectors, selenium-webdriver

Solution

You can use linktext or xpath as follows:

driver.findElement(By.xpath("//a[text()='selectthistext1']"));
//OR
driver.findElement(By.linkText("selectthistext1"));

You may also look at the answer: Need to find element in selenium by css and Writing cssselector expression for webDriver using attribute matching

Problem

I have a tabel with more rows and I need to look for specific "selecttext1". -class myclass is not enough, because it is used for every row -href="#/test/id_var1 it's changing every time and I don't know its value ``` <td class="myclass"> <a class="ng-binding" href="#/test/id_var1">selectthistext1</a> </td> <td class="myclass"> <a class="ng-binding" href="#/test/id_var2">selectthistext2</a> </td> ```

Original source

Related problems