cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove unwanted "/" from a string

SOLVED
Contributor

How to remove unwanted "/" from a string

I  am using FullName property of a label object and then splitting the string to get the Full Name of Dynamic parent. 

This FullName Property returning the string as :"Mobile.Device(\"iPad\").Process(\"iA360 StageTest\").Window(0).TableView(0).TableViewCell(0, 2). Label(\"Gallo PICO\", 0)".

I am unable to remove "\" from the string using replace method or split method of javascript.Aways getting syntax error because of "\'. Can some guide me how can I remove "\" from the above string and get below string

"Mobile.Device("iPad").Process("iA360 StageTest").Window(0).TableView(0).TableViewCell(0, 2). Label("Gallo PICO", 0)".

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Leader

Re: How to remove unwanted "/" from a string

Hi, meenakshiyadav1 ,

 

I have made you a film showing my work with the "FullName" property of a given object.

 

The video shows that you don't need to format a sequence of characters to create an object from such a sequence of characters taken from the "FullName" property.

 

The problem you are presenting does not concern the character "\" at all. In programming languages, such a "\" character in a string means running away from special characters (in your case it is a " character) because the whole string is enclosed in double-quotes.

 

So the correct character to remove from the string is " and not {What you see on the video}.

 

Summary of the film:


1) newStr -> represents the division of the character string into an array by " which may allow you to manipulate the array after it is connected. Note that if you glue it again in the string it will again show up "\" because it's an escape sign from special characters!

 

2) WWFUllName, ReplaceWWWFUllName, ReplaceWWFUllName2
Here you can see that it is not possible to format this string using a character \ you can do it by " (as above)

 

3) evalObjECT and result
Create an object from a string of characters taken from the FullName property and then extract the property from it.

 

Is that what you mean?

 

In general, know that you can dynamically search for such elements using .find() by looking at the structure of objects and not only downwards but also upwards using a property such as .Parent.

 

Let me know if this helped you.

 

View solution in original post

12 REPLIES 12
Community Leader

Re: How to remove unwanted "/" from a string

Hi

 

Remember that .replace("\") only removes first symbol occurence in string.

 

What You can do is use regexp like this on your's string:

 

string.replace(/\\/g, "\\");

/g - means that You want to replace all signs of the symbol.

 

check these topics:

 

https://stackoverflow.com/questions/4566771/how-to-globally-replace-a-forward-slash-in-a-javascript-...

 

https://stackoverflow.com/questions/2479309/javascript-and-backslashes-replace

Contributor

Re: How to remove unwanted "/" from a string

 Thanks for the quick reponse. The main issue I am facing is that I need to replace single backslash "\" with "".  eg. "Mobile.Device(\"iPad\") should be Mobile.Device("iPad").

It seems Testcomplete is using this "\" just before " to make it litteral ". I need this single backslash to be removed. Below is my code:

var FName =Object.FullName   //  Results :"Mobile.Device(\"iPad\").Process(\"iA360 StageTest\").Window(0).TableView(0).TableViewCell(0, 3).Label(\"Gallo PICO\")"
var str = FName.split("\","")  ///This give error " Invalid or Unexpected token" 

 

 If I do ..var str = FName.split("\/g","")  // This does not do anything i get a blank string.

Community Leader

Re: How to remove unwanted "/" from a string

Alright, try this one:

 

var t = a.split('"').join("''");

Smiley LOL

Highlighted
Community Hero

Re: How to remove unwanted "/" from a string

If you have the child object... why do you need the full string to find the parent?  There should be a property on the child object called "Parent" which will take you directly there.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Contributor

Re: How to remove unwanted "/" from a string

@tristaanogre I am finding the child object using Find All children method applied to a grand Parent object as the parent is dynamic . When I try to access the Parent property of this child objects it does not return the Parent instead it returns the grand Parent to me, maybe because I am finding the object using grandparent. 

 

@Wamboo I am confused as to how to use your suggestion. Can you please give me a bit more elaborative example. I need to remove \ .

Community Leader

Re: How to remove unwanted "/" from a string

Hi,

 

To help you better I need to know what do You want to do after formatting this string?

 

What will be your next step?

 

If you .split('"') and .join(' ') You will get the same result because this sign /" is again because it means "escape of the special characters in the string.

Contributor

Re: How to remove unwanted "/" from a string

My Next step is using eval on that string to get the objects and perform the action on that object.

So I need this string to be in correct form of an Alias Name e.g. "Mobile.Device("iPad").Process("iA360 StageTest").Window(0).TableView(0).TableViewCell(0, 3).

Community Leader

Re: How to remove unwanted "/" from a string

But, why You are working with an object like that?

 

You can't map it into NameMapping repository?

Contributor

Re: How to remove unwanted "/" from a string

No, It can not be mapped in the repository as this table view cell object had a dynamic index and it depends upon the no. of record present in the parent table objects at any point in time. I need to get the count of the objects in the table, run a loop with that count and access this table view cell objects to check a particular child object and perform an action on that child objects

So I do not have any other option but to work with this dynamic table view cell objects to access its child objects.

 

can you please suggest me how can I remove "/" from the above mentioned string. so that I can have Full name in correct format.  (Please refer the details above for the required correct string)