1

I'm using Selenium WebDriver and Python 3 and I'm trying to retrieve part of the text of the element.

<div id="ConfirmInfo" class="row">
                    <h3>Confirmation #: S1234567890 </h3>
</div>

How can I retrieve just "S1234567890" without "Confirmation #: "?

1 Answer 1

1
element_text = driver.find_element_by_tag_name('h3').text
#split element_text into ['Confirmation', '#:', 'S1234567890']
split_text = element_text.split(' ') 
confirmation_num = split_text[2]

Selenium provides you with tools to get the text from an element, but if you want to get only a part of the text from the element, AFAIK you have to get the text from the element and then manipulate the string until you have the part you want.

Sign up to request clarification or add additional context in comments.

Comments

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.