Forum Discussion
Please give us more specifics so we can give you a better answer.
It helps a lot if you show us exactly what you tried, what results you got, and what results you wanted instead.
I am trying to verify property text of a Web Page table, but it has a bunch of control chars (\n \t) that I want to ignore:
aqObject.CheckProperty(browser.pageUatUlineComProductDetailH101.form.panelDvchart.table.table, "textContent", cmpEqual, "\n\nMODELNO.\nPRICE EACH\nADD TOCART\n\n\n1\n2\n6+\n\n\nH-101\n$17\n$15\n$13\n\nADD\n\n", false);
When I run the CheckProperty with the cmpEqual test, I simply want to ignore the newline and tab characters.
Thanks,
C
cauline wrote:
I am trying to verify property text of a Web Page table, but it has a bunch of control chars (\n \t) that I want to ignore:
You could process the textContent value to remove extra whitespace and replace the control characters with usual spaces:
var str = browser.___.textContent; str = str.replace(/\s+/g, ' '); // replace consecutive \r \n \t etc. with a single space str = aqString.Trim(str); // remove leading and trailing whitespace aqObject.CompareProperty(str, cmpEqual, "expected value", false);
Note the usage of CompareProperty instead of CheckProperty, because we check the variable value (str) rather than the textContent property directly. Also make sure the expected value has the same normalized format as the value being checked.
- tristaanogre9 years agoEsteemed Contributor
First, change cmpEqual to cmpMatches.
I can't attest to the validity of the regular expression... I honestly have never gotten the hang of writing those... something I need to get better at. But, if you're going to use a regular expression, you need to use cmpMatches. See https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.html