0

For example:

<div class="xpto">Some text</div>

How can I get the "Some text" ?

I have this:

self.driver = webdriver.Chrome()
message_received = self.driver.find_element_by_xpath('//*[@id="mount_0_0"]/div/div[1]/div[1]/div[5]/div[1]/div[1]/div[1]/div/div/div/div/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[3]/div/div[36]/div[4]/div/div/div/div/div[1]/div') # xpath of element
text_obtained = message_receiver. #dont know what to put here
        
DebanjanB
  • 118,661
  • 30
  • 168
  • 217

2 Answers2

0

Show that part of webpage you want to get. And try message_received.text

MetraDZ
  • 55
  • 6
0

To get the innerText Some text you can use either of the following Locator Strategies:

  • Using xpath and text:

    print(self.driver.find_element_by_xpath('//*[@id="mount_0_0"]/div/div[1]/div[1]/div[5]/div[1]/div[1]/div[1]/div/div/div/div/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[3]/div/div[36]/div[4]/div/div/div/div/div[1]/div').text)
    
  • Using xpath and get_attribute("innerHTML"):

    print(self.driver.find_element_by_xpath('//*[@id="mount_0_0"]/div/div[1]/div[1]/div[5]/div[1]/div[1]/div[1]/div/div/div/div/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[3]/div/div[36]/div[4]/div/div/div/div/div[1]/div').get_attribute("innerHTML"))
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217