Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get text that appear on page from div?

The page source look like this:

    <div class="caption">
                        <div id="question_speaker" style="display: none;"><img 
    src="../server/static/loudspeaker.png"></div>
                        <div class="translations">explain</div>
                        <div>&nbsp;</div>
                    </div>

I’m trying to get "explain" to text variable in python.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

CSS:

div.caption div#question_speaker+div

XPATH:

//div[@class='caption']//div[@id='question_speaker']//following-sibling::div

Before using them make sure that they are unique in HTML-DOM

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath/css and see, if your desired element is getting highlighted with 1/1 matching node.

Code:

print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='caption']//div[@id='question_speaker']//following-sibling::div"))).text)

You’ll need below import:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading