user2464219
user2464219

Reputation: 105

Selenium Webdriver c# select a specific table cell when the cell is present

I have launched & navigated to a popup search page, where I select some search criteria. I then select a search button and a grid/table of entries is displayed. The table will only be populated with entries if the search criteria has found entries based on the input given (Its basically a hotel rate search, if you look for a hotel in a certain area it will return rates. No hotels available = no rates).

So I have started these lines of code like this:

// Selects the cell you require from the table grid (tr=row td=cell nth-child=number down)
mWebDriver.SelectElement(By.CssSelector("#grd_ResultsRateByRoom tr td.Selectable"));
if (tableCells == 0)
    throw new System.Exception("No rate available");

Now all I want to do is return an alternate line of code to click any valid entry if there is an entry displaying (I have already defined a class for ClickElementById, but using the standard tableCell.click; on the end of this does not function correctly?

enter image description here

Upvotes: 0

Views: 3931

Answers (2)

user2464219
user2464219

Reputation: 105

I think I have solved it (using both the FindElement with By.Xpath and By.CssSelector methods).

One that worked best was:

mWebDriver.SelectElement(By.CssSelector("#grd_ResultsRateByRoom tr td.Selectable")).Click();

Upvotes: 1

Stormy
Stormy

Reputation: 641

Try using XPath to locate the specific cell. You can locate it via FirePath extension for FireFox

Upvotes: 1

Related Questions