Find text on a page using Python Selenium

Question:

Can I find the element on the page by the text: "Confirmation link:", and copy from there only what comes after the ":"?

How it looks on the page:

<div class="msg-body P_wpofO mq_AS" data-test-id="message-view-body-content"><div class="jb_0 X_6MGW N_6Fd5"><div><div id="yiv5768405894">Hello,
<br>
<br>
Thank you for registering at FaucetPay. However, before you getting running on the site, you've to confirm your email address. Click <b><a rel="nofollow noopener noreferrer" target="_blank" href="http://email.ml.faucetpay.io/c/eJxNT7uOxCAM_JpQRmBjAgXFNfcbJ7CNklOyrHJJsX9_dLvSFPPQ2BrNLgSXgiUiI7l4FGCzZbAANqJz5AFp5pJSTc0xuEXVyeTtsc-t3KzXs7zmrZs1F5RolZhJSbVFkAW91eLrsujIzJ7X63r-Tfg1wffAZ3_IwtzvxzUY90fbzuPn7UhtpJVEkaJ6jKxYbIgQxnmEyhUkSErixzdE11C9F63JNiRoUMyZuR_HvR961u1Xx4BXWXufh_sPy8pPlQ">here</a></b> to confirm your account, or copy the link below directly to confirm your email address.
<br>
<br>
<b>Confirmation link: https://faucetpay.io/account/confirm_account/...</b>
<br>
<br>                
Regards,
<br>
FaucetPay
<br>
<br>
<small>If you didn't apply for an account, please ignore this email and you won't be bugged again.</small><img width="1px" height="1px" alt="" src="https://ecp.yusercontent.com/mail?url=http%3A%2F%2Femail.ml.faucetpay.io%2Fo%2FeJwNzDEOwyAMQNHTlBFhGztl4DBgjJIqiCpqhty-jP8N3zKIQJLAzK7lEqmhuiNjQAxvAuCIxF5LSjV1UITNDNorhnH6Xm6137c8_phuzwWlEzL3rQLE3pSFVimrCkgjd2WdY9znsKseH1uTp-xz-qV_3GYn9A&amp;t=1661961265&amp;ymreqid=21542e5c-ba48-29be-1cc7-00000001a100&amp;sig=6gRNlw6iByYWJxMZjHioTA--~D">
</div></div></div></div>
Asked By: Ambamamba

||

Answers:

You need to first identify the element using xpath and then get the text of the element.
Then split() the text with "Confirmation link:" which will return an zero based array and you need to get the last index of that array.

Code:

messageText=driver.find_element(By.XPATH , "//div[@data-test-id='message-view-body-content']//b[contains(., 'Confirmation link')]").text
linkFromText=messageText.split("Confirmation link:")[-1]
print(linkFromText.strip())
Answered By: KunduK
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.