normalize-space(string)
str = " cher cher tech "
normalize-space(string) // outputs "cher cher tech"
With code example
html code
<label> who cares about spaces </label>
xpath
//label[normalize-space(text())='who cares about spaces']
<button type="button">Blueberry</button> (Blueberry is text here)
xpath with text : //button[text()='Blueberry']
But when the text is dynamic we have to use contains function along with text function. For this to work some part of the string must be static.
<button type="button">*****berry</button>
xpath with text : //button[contains(text(),'berry')]
Syntax :// tagname[text(), 'sourceCaseContent', 'targetCaseContent'), 'value']
$x("//xpath")
XPath and CSS work almost with the same speed; even on this website, we have performed the tests couple of times but there is no considerable difference in speed.
So when the interviewer asks this kind of a question you should be knowing.
//input/../
// form button using input tag
<input type='button' value='ABCD'>
Xpath : //input[@type='button']
// form button using the button tag
<button>XYZ</button>
Xpath : //button
<button aria-label="Close" onclick="myDialog.close()">X</button>
Xpath : //button[@aria-label='Close']
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.