1

Consider i have this HTML:

<span class="bla">Create New</span>

How can i get this element ?

I try:

span:contains("Create")

2 Answers 2

1

You can use the "by xpath" locator:

driver.findElement(By.xpath("//span[. = 'Create New']"));
Sign up to request clarification or add additional context in comments.

4 Comments

Can i also have it with css ?
@davidhol from what I know, no, you have to use by xpath: stackoverflow.com/questions/14595149/….
What does the dot doing ?
@davidhol the "dot' refers to the span element's text.
0

EDIT - xpath selector to get by text:

driver.findElement(By.xpath("//span[contains(.,'Create New')]"));

3 Comments

The question is "Get HTML element by text".
This class named bla appears several times.
Updated to get by text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.