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 data-test-id="message-view-body-content"><div ><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://email.ml.faucetpay.io/o/eJwNzDEOwyAMQNHTlBFhGztl4DBgjJIqiCpqhty-jP8N3zKIQJLAzK7lEqmhuiNjQAxvAuCIxF5LSjV1UITNDNorhnH6Xm6137c8_phuzwWlEzL3rQLE3pSFVimrCkgjd2WdY9znsKseH1uTp-xz-qV_3GYn9A&t=1661961265&ymreqid=21542e5c-ba48-29be-1cc7-00000001a100&sig=6gRNlw6iByYWJxMZjHioTA--~D">
</div></div></div></div>
CodePudding user response:
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())