0
<div _ngcontent-tpr-c123="" class="panel panel--bordered">hac-action: 1: /wae:wae/wae-ha:ha-config/ha-data-sync</div>
old_config_xpath = "//div[contains(text(),'hac-action')]"
element_value = wae_base_params[self.driver_key].find_element_by_xpath(old_config_xpath).text

element_value is empty.

note: the above HTML code is not a visible content on the webpage

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38

2 Answers2

0

The way any element is located is when it's on the DOM.

The way to be sure the element is located on the DOM is using WebDriverWait with expected_conditions:

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


wait = WebDriverWait(browser, 10)

element_value = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(text(),'hac-action')]]"))).text
Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
0

I didn't see the page source of the website, but please test the following code, and let me know the result. In the past, I've used get_attribute('innerHTML') instead of 'text' and it worked properly. I'd be very happy if you let me know the result.

old_config_xpath = "//div[contains(text(),'hac-action')]"
element_value = wae_base_params[self.driver_key].find_element_by_xpath(old_config_xpath).get_attribute('innerHTML')
Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
Ahmed Mamdouh
  • 696
  • 5
  • 12
  • This can work in some cases you can read more [here](https://stackoverflow.com/questions/24427621/innertext-vs-innerhtml-vs-label-vs-text-vs-textcontent-vs-outertext/32107178), as OP noted in the question the element is not on the page: hence my answer... – Moshe Slavin Aug 30 '20 at 13:52