0

After I select a tag when I try to get HTML contents. it is converting the values such as 0.102 to 0,102. There are some values like 1,203 they remain the same. but float type is being wrongly converted.

I'm new so I haven't tried much

element = driver.find_element_by_css_selector("div.widget-equity-technical-key-data table")
html = element.get_attribute('innerHTML')

say a column with values 1,201 and 0.102 expected at least 1201 and 0.102 but the actual output is 1,201 and 0,102

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Dhanush C
  • 1
  • 7

2 Answers2

0

post findElement method you can use replace method on strings and then perform assert

for value 1,201

String s1 = s1.replace(',', '');

for value 0,102

String s1 = s1.replace(',', '.');
Amit Jain
  • 4,389
  • 2
  • 18
  • 21
  • I cant do it. As soon as i convert it into html . is gone i cant know which one is decimal and which is whole number. after i convert all i get is 1,201 and 0,102 cant hard code stuff – Dhanush C Jul 05 '19 at 08:44
  • don't convert it to HTML, try using direct string after find element and then using get_attribute method. – Amit Jain Jul 05 '19 at 08:58
0

The relevant HTML would have been helpful to debug the issue in a better way. However to retrieve the innerHTML using Selenium you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.widget-equity-technical-key-data table"))).get_attribute('innerHTML'))
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='widget-equity-technical-key-data']//table"))).get_attribute('innerHTML'))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352