Turgut Kanceltik
Turgut Kanceltik

Reputation: 639

my selenium test C# in chrome. Click property

While working on this project, I have encountered an exception. It is running firefox, but will not run in chrome.

        [Test]
public void TheBtcTraderDenemeTest()
{
    _driver.Navigate().GoToUrl(_baseUrl);
    Thread.Sleep(1500);
    _driver.FindElement(By.ClassName("btn btn-cust")).Click(); //*** Exception location is this one.

An exception of type 'OpenQA.Selenium.IllegalLocatorException' occurred in WebDriver.dll but was not handled in user code

Additional information: Compound class names are not supported. Consider searching for one class name and filtering the results.

Any ideas on what is going on would be appreciated.

Upvotes: 0

Views: 239

Answers (2)

Arran
Arran

Reputation: 25076

By.ClassName will only accept a single CSS class name, by it's very name & definition. You are giving it two.

Two is 1) btn and 2) btn-cust.

Therefore it's no longer a "class name" selector but rather a general CSS Selector.

So you need to do either of the following:

Use only one of them, probably btn-cust with By.ClassName or keep with what you have but put it into a CSS selector:

By.CssSelector("btn btn-cust")

FWIW, the exception message tells you exactly what is wrong and is saying the exact same thing as we are here. Please check out your exceptions when they are thrown. They aren't there for fun.

Upvotes: 0

mybirthname
mybirthname

Reputation: 18137

Additional information told you everything. You should choose one of the classes, not both of them

Upvotes: 2

Related Questions