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

Was it helpful?

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:

  1. //span[@class='ms-cui-ctl-largelabel'][contains(., 'New')][contains(., 'Map')]

  2. //span[contains(., 'New')][contains(., 'Map')]

  3. //span[@class='ms-cui-ctl-largelabel']

  4. //span[@class='ms-cui-ctl-largelabel'][contains(., 'New')]

  5. //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',' ','')]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top