Monday, May 21, 2018

How to select NOT element with specific string in colon attributed name

Leave a Comment

I have couple of elements like this:

<g transform="matrix">    <image xlink:href="data:image/png" width="48"> </g> <g transform="matrix">    <image xlink:href="specyfic" width="48"> </g> <g transform="matrix">    <image xlink:href="specyfic" width="48"> </g> 

I want to select element which would NOT have 'specifyc' in name. The problem is that sometimes there are couple of that NOT elements and sometimes there are none. The NON specyfic image count is always one.

I cannot accomplish that because of ':' in attribute name.

I tried this:

  public static getEventIconOnMap: ElementFinder =     element.all(by.css('image[width="48"]:not(image[xlink\\:href*="specyfic"'))).last(); 

2 Answers

Answers 1

Your code does not make much sense to me and have no idea how to test it, but I think the following code will work. Try escaping the character like this:

public static getEventIconOnMap: ElementFinder =     element.all(by.css('image:not([xlink\:href*=specyfic]')).last(); 

Here is a CSS selector that works, so adjust this to your code:

image:not([xlink\:href*=specyfic]) {   // your code } 

Here is a working fiddle - it's not the exact code you are using, but I wrote it as a css selector: https://jsfiddle.net/x4gsr658/

Answers 2

I don't know if your problem is exactly that or that is just a typing error while writing your answer, but I've noticed something wrong here:

public static getEventIconOnMap: ElementFinder =     element.all(by.css('image[width="48"]:not(image[xlink\\:href*="specyfic"'))).last(); 

You have erroneously excaped the : character and you haven't closed your selector inside the string, instead you have closed too many expression outside from the quotes, you'll need to rewrite that to:

public static getEventIconOnMap: ElementFinder =     element.all(by.css('image[width="48"]:not(image[xlink\:href*="specyfic"])')).last(); 

Furthermore, you can't combine multiple selectors inside a :not() pseudo: you wrote :not(image[xlink\:href*="specyfic"]), but the browser won't be able to parse that, which is a syntax error!
Considering the selector already restricts the selection to only <image> elements in the first part (image[width="48"]), your negation doesn't need to ensure the tag name. So, correct your selector to following:

image[width="48"]:not([xlink\:href*="specyfic"]) 

Here's the corrected full code:

public static getEventIconOnMap: ElementFinder =     element.all(by.css('image[width="48"]:not([xlink\:href*="specyfic"])')).last(); 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment