You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im trying to capture the inner text of an element locator, and verify if it contains a certain string.
The inner text of this element has a new line character, like below,
'QA auto testing medicine\n240205-1 - 14105'
IDE won't let me go through , it give the error below
executeScript on return document.querySelector("tbody tr:nth-child(1) td:nth-child(2)").innerText.includes(${invoice_firstItem}); with value is_include_firstItem
Failed:Bad control character in string literal in JSON at position 10 (line 1 column 11)
So I have to deal with \n first, try to eliminate it with javascript function replace(). it still gives the error, and I don't think it is a syntax error
executeScript on let a=document.querySelector("tbody tr:nth-child(1) td:nth-child(2)").innerText; let b=a.replace((/\n/g, ''); return b.includes(${invoice_firstItem}); with value is_include_firstItem
Failed:Invalid regular expression: missing /
Wonder if the original string has special character, how we can do the assertion
@heandping - I encountered this when using v4 at work. Actually, I changed waitForText in v4 to replace newlines with spaces and trim trailing and leading spaces on both entries using the below logic:
Thanks for your help @toddtarsi , it works
I tried to use /\u00A0/g instead of /\n/g in the replace function, error gone, which makes me think a little about this, so the original text which is 'QA auto testing medicine\n240205-1 - 14105', \n is not a real \n, it may be a non-breaking space, so when I try to replace \n, it failed.
Very interesting! I don't mean to sound confused, but if you have any other optimizations to propose to remove non-intentional characters, let me know and I can look at doing em. I'm still feeling out the adjustments here!
Dear support,
Im trying to capture the inner text of an element locator, and verify if it contains a certain string.
The inner text of this element has a new line character, like below,
'QA auto testing medicine\n240205-1 - 14105'
IDE won't let me go through , it give the error below
executeScript on return document.querySelector("tbody tr:nth-child(1) td:nth-child(2)").innerText.includes(${invoice_firstItem}); with value is_include_firstItem
Failed:Bad control character in string literal in JSON at position 10 (line 1 column 11)
So I have to deal with \n first, try to eliminate it with javascript function replace(). it still gives the error, and I don't think it is a syntax error
executeScript on let a=document.querySelector("tbody tr:nth-child(1) td:nth-child(2)").innerText; let b=a.replace((/\n/g, ''); return b.includes(${invoice_firstItem}); with value is_include_firstItem
Failed:Invalid regular expression: missing /
Wonder if the original string has special character, how we can do the assertion
Selenium Version: 3.17.2
Chrome version: 124.0.6367.79 (Official Build) (arm64)
The text was updated successfully, but these errors were encountered: