Getting OpenQA.Selenium.InvalidSelectorException Trying to Find an Element

644 views
Skip to first unread message

Chrissy Freiboth

unread,
Mar 29, 2020, 2:58:18 AM3/29/20
to Selenium Users
I am loading the url https://www.pinterest.com/login in the chrome driver and trying to find the Login Button so I can execute the click method but I get the exception below when executing this code.

OpenQA.Selenium.InvalidSelectorException - Compound class names not allowed. Cannot have whitespace in class name. Use CSS selectors instead.

Code:

IWebElement ele1 = driver.FindElement(By.ClassName("red SignupButton active"));

Here is the button code.

<div data-test-id="registerFormSubmitButton"><button aria-label="" class="red SignupButton active" type="submit" style="border: 0px; height: 36px; display: inline-block; border-radius: 20px; -webkit-font-smoothing: antialiased; padding: 0px 18px; font-size: 15px; font-weight: bold; outline: none; box-shadow: none; cursor: pointer; margin-top: 10px; vertical-align: middle; text-align: center; background-color: rgb(230, 0, 35); color: rgb(255, 255, 255); width: 100%;"><div>Log in</div></button></div>

There is no name or ID, just a class name. Is there some other method I can search by to allow the driver to find the button?

Jim Evans

unread,
Mar 29, 2020, 5:30:49 PM3/29/20
to Selenium Users
Just like the exception message says, you should use CSS Selectors instead.

driver.FindElement(By.CssSelector("button.SignupButton.active.red"))

Note that order doesn’t matter for the classes to be found in the class attribute of the element, and that each term separated by white space is considered a separate class for the element.

Kogul S

unread,
Mar 30, 2020, 1:51:16 AM3/30/20
to seleniu...@googlegroups.com
Hi, 

This solution will help, please go through the below link:

Thanks & Regards, 
S. Kogul 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6f032849-8f9f-42a0-82c9-d2e19f99cc5d%40googlegroups.com.

Chrissy Freiboth

unread,
Apr 6, 2020, 11:49:54 AM4/6/20
to Selenium Users
Thanks. I got it to work.
Reply all
Reply to author
Forward
0 new messages