1

Is it possible for Selenium to parse the source-code and locate specific text which is "Last updated" and then copy the whole line with date and time into a variable ?

HTML - code to be coped into a variable

Last updated: <strong>31.12.2015 17.46</strong>

1 Answer 1

2

Locate the strong element that has this specific preceding text sibling:

driver.find_element_by_xpath("//strong[contains(preceding-sibling::text(), 'Last updated: ')]").text
Sign up to request clarification or add additional context in comments.

3 Comments

That didn't work gave me this error: ' selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//strong[preceding-sibling::text() = 'Last updated: ']"}
@user3580316 could be several reasons for that - can you provide the URL of the page you are working with so I can reproduce the problem too? Thanks.
Since this is a page you enter after authentication, I am not able to do so. However I can provide you with the source code which may be to help ? Just look for "Last updated" and you will find the string. dropbox.com/s/1sbhtgnjh4yg4do/source-code.txt

Your Answer

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