Reputation: 23
From the html code I am unable to get the edit button in selenium c#
<button class="pt-buttonbase pt-button pt-bordered pt-icon-and-text" data-iconurl="../content/icons/Edit.png" data-bind="click: $root.editTemplate" data-toolkit="button">
Upvotes: 2
Views: 397
Reputation: 66
Ask whomever the developer is to give the button a unique ID. Then search it by ID.
Upvotes: 1
Reputation: 329
I like using CssSelector:
You might not need to use all 4 class names, but this will work:
By.CssSelector(".pt-buttonbase.pt-button.pt-bordered.pt-icon-and-text"));
You can always check in your browsers console to see if classes are unique using JQuery like this:
$(".pt-buttonbase")
If that is not unique you can keep adding the other class names until you only get one object as a response.
Upvotes: 0
Reputation: 6940
If you can provide some HTML it'll be better. Note that when you are using XPath with class - you'll receive first element matching your condition. And even if it's correct - you will get not required button. In this case use indexing e.g. [1].
Upvotes: 0
Reputation: 8274
Not knowing what you've tried and haven't tried, I would suggest xpath. Assuming you have a WebDriver variable, Driver
:
WebElement EditButton = Driver.FindElement(
By.XPath("//button[@data-iconurl='../content/icons/Edit.png']"));
Upvotes: 0