Alternative solution using normalize-space()
//span[@class="ms-cui-ctl-largelabel" and normalize-space()="New Map"]
Question
Following is the code of a button in my application.
<span class="ms-cui-ctl-largelabel" unselectable="on">
New
<br>
Map
</span>
</a>
</span>
I want to click on that button and using Selenium Webdriver for it. I tried multiple combinations but it's not working for me. Following are the different xpaths which I tried
1. By.xpath("//span[contains(@class, 'ms-cui-ctl-largelabel') and text() = 'New/nMap']"));
2. By.xpath("//span[contains(@class, 'ms-cui-ctl-largelabel') and text() = 'New/r/nMap']"));
3. By.xpath("//span[contains(@class, 'ms-cui-ctl-largelabel') and text() = 'New Map']"));
Could someone please help ?
Thanks
Solution
Alternative solution using normalize-space()
//span[@class="ms-cui-ctl-largelabel" and normalize-space()="New Map"]
OTHER TIPS
You can use anyone of these xpath:
//span[@class='ms-cui-ctl-largelabel'][contains(., 'New')][contains(., 'Map')]
//span[contains(., 'New')][contains(., 'Map')]
//span[@class='ms-cui-ctl-largelabel']
//span[@class='ms-cui-ctl-largelabel'][contains(., 'New')]
//span[@class='ms-cui-ctl-largelabel'][contains(., 'Map')]
All are tested xpath.
You can use the following xpath to find span by text with <br>
and class:
//span[contains(.,'New') and contains(.,'Map') and @class='ms-cui-ctl-largelabel']
Try using this line:
//span[translate(string(),' ','')=translate('New Map',' ','')]