简体   繁体   中英

Selenium XPath: How to find text within a span class tag?

I have several objects that look exactly the same, except for the text within 'span class'. In the example below, I need to locate the phone number, '+15551234567':

<span class="contact-number">+15551234567 </span>

I have tried several css selectors and xpath queries and have not had much luck.

Any help would be greatly appreciated!

css seletor for this:

span.contact-number

xpath:

//span[@class='contact-number']

or

//span[text()='+15551234567 ']

and you can get text from locator in that way:

webdriver.findElement(By.xpath("locatorHere")).getText();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM