2

I have below HTML sample code:

<a href="" title="Design" class="reMode_design  reMode_hover">
    <span>Design</span>
</a>

<a href="" title="Design" 
 class="reMode_design  reMode_hover reMode_selected">
    <span>Design</span>
</a>

Here, i need to define CSS for the 1st href element and want to ignore 2nd element which has this class "reMode_selected". How to define css for the 1st element by ignoring 2nd element???

I don't want to use Xpath and I am looking for like this below CSS selector:

element :fld_link, "[title='Design'] [class !='reMode_selected']"

This format doesn't work in SitePrism Cucumber. Need Help on how to exclude a attribute name in CSS selector...

Guy
  • 46,488
  • 10
  • 44
  • 88
ASM
  • 709
  • 2
  • 8
  • 27

4 Answers4

2

You can do this with cssSelector

driver.find_element(:css,".reMode_design:not(.reMode_selected)")
Guy
  • 46,488
  • 10
  • 44
  • 88
  • I didn't try that code yet. But i will let you know and accept the answer if that works. Thanks – ASM Feb 17 '16 at 22:15
1

You can do with this css locator a[title='Design']:not([class*='reMode_selected'])

0

Have you tried using an xpath to locate the element? Perhaps something like: //a[contains(@title, 'Design') and not(contains(@class, 'reMode_selected'))]

References/Examples:

Using not in xpath

Using and in xpath

Community
  • 1
  • 1
Jacob Murphy
  • 1,387
  • 2
  • 10
  • 18
  • I don't want to use xpath. I forgot to mention. If its there any way i can use css instead your given xpath ??? – ASM Feb 17 '16 at 20:32
0

You can use the not: css prefix as others have mentioned or you could combine a capybara query to return the element based off it's text, or use a waiter.

SitePrism is quite advanced, so pretty much all options are open to you

Luke Hill
  • 460
  • 2
  • 10