melanyy
melanyy

Reputation: 33

Get value with Selenium C#

I have

`<button class="button button--chromeless" data-action="select-anchor" data-action-value="fba4">Top highlight</button>`

I need get result "fba4" from data-action-value.

I tried:

IWebElement ell = driver.FindElement(By.CssSelector("button[data-action-value]"));

I think that I need be based on Top highlight to get value fba4 but I don't know how?

Upvotes: 1

Views: 15577

Answers (2)

Shubham Jain
Shubham Jain

Reputation: 17553

Use .GetAttribute("data-action-value")

 string element  = driver.FindElement(By.CssSelector("button[data-action-value]")).GetAttribute("data-action-value");

You can also use below Xpath

//button[@class='button button--chromeless']/@data-action-value

You can use

string element  = driver.FindElement(By.ClassName("button button--chromeless")).GetAttribute("data-action-value");

Hope it will help you :)

Upvotes: 4

amitbobade
amitbobade

Reputation: 510

To get 'fba4' from the above HTML, try-

string ell = driver.FindElement(By.CssSelector("button[class='button button--chromeless']")).GetAttribute("data-action-value");

Upvotes: 1

Related Questions