问题
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
回答1:
Alternative solution using normalize-space()
//span[@class="ms-cui-ctl-largelabel" and normalize-space()="New Map"]
回答2:
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.
回答3:
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']
回答4:
Try using this line:
//span[translate(string(),' ','')=translate('New Map',' ','')]
来源:https://stackoverflow.com/questions/23268927/how-to-use-xpath-for-extracting-text-between-br-tag