0

enter image description hereenter image description hereenter image description here

Please find image, that I want to click on. Functionality of image is dropdown button. By clicking on v,+ and on name will get drop down.

I used this code:

 driver.FindElement(By.ClassName("CommandBarItem beak-anchor command is-focused")).Click();

Getting an error that compound class names are not permitted

Please can any help? Thanks in Advance!

  • Not able to understand your problem. Can you give more details about your HTML and the scripts that you are using? and also maybe a screenshot of the actual error. – IAmMilinPatel Sep 30 '16 at 4:30
1

For locating elements using the ClassName you are not allowed to use compund class names. For example, in your case the element has 3 CSS classes and when you enter all of them in the driver.FindElement(By.ClassName(" it is considered as a compound class name. This means that, it is considered as single class with spaces, which is not allowed in locating element with ClassName.

Use a single class name to locate your element. If it doesn't have a unique class, then use CSSSelector (something like driver.FindElement(By.CssSelector("input[name='CommandBarItem']"));) or an even better option would be to use XPath. You can get the XPath of the target element using the FirePath extension of Mozilla FireFox.


Addendum As per the updates in the Question,

You want to test whether clicking one of the 3 links (+, New and v) will open a drop down list or not.

BUT

With your test script you are trying to click the div that encloses the 3 links and not the links themselves.

You should test each of the three links separately. Try,

Clicking + icon:

driver.FindElement(By.ClassName("CommandBarItem-Icon")).Click();

Clicking NEW link:

driver.FindElement(By.ClassName("CommandBarItem-CommandText")).Click();

Clicking v (down arrow):

driver.FindElement(By.ClassName("od-CommandBarItem-down")).Click();

OR TRY

driver.FindElement(By.ClassName("od-CommandBarItem-link")).Click();

You can try the same with CSSSelector or with XPath as well. Just remember, DON'T TRY TO CLICK THE DIV. CLICK THE LINKS THAT HAVE AN ACTION TO OPEN DROP DOWN LIST WRITTEN ON.

  • Even I tried with Xpath and css selector, Error unable to locate element – santhosh nayak Sep 30 '16 at 5:51
  • You know like I asked in an earlier comment on the question, if we could see your HTML (target) and the test scripts, it'll be better for us to help! – IAmMilinPatel Sep 30 '16 at 5:53
  • <span class="CommandBarItem-icon" data-bind="component: { name: 'od-icon-glyph', params: { icon: $parent.icon, badge: $parent.iconBadge } }, attr: { 'is-flipped': $parent.positionIconRight }"><i class="od-IconGlyph ms-Icon ms-Icon--Add od-IconGlyph--visible" data-bind="classes: { base: iconClasses, mappings: { 'od-IconGlyph--badged': badge, 'od-IconGlyph--visible': icon } }, with: badge"></i></span> – santhosh nayak Sep 30 '16 at 5:54
  • That's half of what I asked for. Now would you be kind and share the other half? Better yet share screenshots of your application HTML AND THE SCRIPT YOU ARE USING TO TEST IT. – IAmMilinPatel Sep 30 '16 at 5:58
  • Please find question with updated image – santhosh nayak Sep 30 '16 at 6:19
0

This is a compound class,And compound classes cant be used in

driver.FindElement(By.ClassName

Try some other way to find the element or use the CSSSelector.

Compound means it contain spaces inside your class name.But selenium is only looking for class names which don't have any spaces in between the class name.

  • If really needed to club class names, I will suggest to use "."[dot] in between two class names
  • Even this is also class name without spaces."CommandBarItem-link" – santhosh nayak Sep 30 '16 at 5:49
0

OK, Use Firefox Selenium IDE to perform the same thing. After recording the step please review the code and check how does Selenium IDE capture that element.

  1. Download FireFox
  2. Download and install Selenium IDE.
  3. Record the steps that you have the issue with "Unable to click on Text link - Observed “InvalidSelectorException” & “Compound class names not permitted”"
  4. After sucsussfully recording the step try play back the steps.
  5. If it successfully playing back then go to Options ->Format and select c# /Nunit/Webdriver.
  6. Then click on "source" tab at the main screen.
  7. There you can find the exact way selenium IDE use to find that elemant.

The code you can see a the Source section is compatible with c# so you can use the same code on your c# project.

  • Okay, and then what's to be done? Can you give more info on the solution you're suggesting? – IAmMilinPatel Sep 30 '16 at 6:01
  • Download FireFox Download and install Selenium IDE. Record the steps that you have the issue with "Unable to click on Text link - Observed “InvalidSelectorException” & “Compound class names not permitted”" After sucsussfully recording the step try play back the steps. If it successfully playing back then go to Options ->Format and select c# /Nunit/Webdriver. Then click on "source" tab at the main screen. There you can find the exact way selenium IDE use to find that elemant. – ChathuD Sep 30 '16 at 6:28
  • Okay, now add this to your answer by editing it. Also append after getting the locator from Selenium IDE how to convert it to the Webdriver code! – IAmMilinPatel Sep 30 '16 at 6:29
  • Thanks @TESTasy :) for showing me the correct path for posting a better answer . – ChathuD Oct 3 '16 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.