user3274919
user3274919

Reputation: 51

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

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>

Upvotes: 4

Views: 28183

Answers (3)

Rajan
Rajan

Reputation: 147

You can locate the button with any of the following CSS selector approach

By Class

Syntax: tag.Classname

By.cssSelector("button.btn addWidgButt bt-block");

By Attribute and Value

Syntax: [attribute='value']

By.cssSelector("button[context='UNIQUE_THING']")

Upvotes: -1

user3487861
user3487861

Reputation: 350

Use the Following CSS Selectors

css=.ng-binding[href*='id_var1'] -- CSS Selector for Link Text selectthistext1

css=.ng-binding[href*='id_var2'] -- CSS Selector for Link Text selectthistext2

Please Let me know is the above CCS Selectors are working or Not.

Upvotes: -1

Husam
Husam

Reputation: 1105

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

Upvotes: 6

Related Questions