Banjaxx
Banjaxx

Reputation: 644

Selenium WebDriver with C# - How can I locate these buttons?

I'm trying to click on each of these buttons but I'm failing to get anything. Even xpath is failing to pick them up. Does anyone have any idea on how to locate these buttons?

<button class="rt-button rt-dialog-button" title="" value="">Close</button>
<button class="rt-button rt-dialog-button" title="" value="">OK</button>

Many thanks for any help

EDIT:

Thanks for trying to help. None of the suggestions worked for me but I did sort it out using:

c#

IWebElement OKButton = driver.FindElement(By.XPath(("//button[@class='rt-button rt-dialog-button'][2]")));

IWebElement CloseButton = driver.FindElement(By.XPath(("//button[@class='rt-button rt-dialog-button'][1]")));

Upvotes: 1

Views: 2735

Answers (4)

Saifur
Saifur

Reputation: 16201

//[.='OK']

if this does not work then you have multiple elements having same text hidden or somewhere on the page

Upvotes: 0

Tema N.
Tema N.

Reputation: 1

I think you can try this xpath:

//button[contains(text(),'Close')]

Upvotes: 0

Richard
Richard

Reputation: 9029

I'd use xpath to find them:

By.XPath("//button[text()='Close']")
By.XPath("//button[text()='OK']")

Upvotes: 3

John Dorlus
John Dorlus

Reputation: 59

You can add an ID, to each element.

<button id="closeButton" class="rt-button rt-dialog-button" title="" value="">Close</button>
<button id="okButton" class="rt-button rt-dialog-button" title="" value="">OK</button>

Then to find it you can do something like

IWebElement element = driver.FindElement(By.Id("closeButton"));
IWebElement element = driver.FindElement(By.Id("openButton"));

I have had times where I was having a hard time with capturing by class and x-path and ID helped.

Upvotes: 0

Related Questions