A non-breaking space prevents line breaks from occurring at a particular point in an HTML document meaning that strings separated with this entity will not be separated and put into separate lines. Space may seem like the most obvious thing ever to an external observer. You hit the ‘space’ key, space appears as expected and you move on. In reality, typing in spaces is quite tricky, and there are numerous ways of going around it in HTML.
I don’t know whether you faced the non-breaking space (nbsp) issue while automating web applications. On my web page, I have the label showing Interval 60 Minutes. I had a situation to validate it, normally we will write relative XPath like //div//div//div[text()=’Interval 60 Minutes’] or we will use starts-with and contains. The interesting part in the DOM developer coded this label as Interval 60 Minutes. In some cases, the developer can be coded like this for extra safety space between words to work for cross-browsers. Sometimes this will be a headache for the QA automation engineers.
I tackled this using \u00a0. This character is a non-breaking space character that can be helped to prevent consecutive whitespace characters from collapsing into a single space. I used the XPath value as //div//div//div[text()=’Interval\u00a060\u00a0Minutes’] to validate the particular element during the automation execution.
From the automation engineer perspective, we should analyze the exact DOM element value prior to writing relative XPath. otherwise, it’s waste of time to debug and correct it. I hope you got an idea to tackle the non-breaking space (nbsp) issue, try to use this concept in your automation script if you have such a situation.
make it perfect!
Leave a Reply