'Negative value error "could not convert string to float:"
Hello im getting "could not convert string to float:" error. I think I need to use the replace command. I am a novice. That's why I couldn't edit the code. :)
def net_both(stoploss_value, takeprofit_value, wait):
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "additional_percent_value")))
try:
time.sleep(.5)
check = driver.find_elements_by_class_name("additional_percent_value")[0]
check.find_element_by_xpath('./span[contains(@class, "neg")]')
negative = True
except NoSuchElementException:
negative = False
if negative:
net_profit = driver.find_elements_by_class_name("additional_percent_value")[0].text.split(" %")
net_value = -float(net_profit[0].replace('−', ''))
profits.update({-net_value: ["Stoploss:", stoploss_value, "Take Profit:", takeprofit_value]})
print(colored(f'Net Profit: -{net_value}% --> Stoploss: {stoploss_value}, Take Profit: {takeprofit_value}', 'red'))
Solution 1:[1]
Try to:
- remove
.text.split(' %') - replace
-float(net_profit[0])byfloat(net_profit.replace('?', '-').rstrip('%'))
if negative:
net_profit = driver.find_elements_by_class_name("additional_percent_value")[0]
net_value = float(net_profit.replace('?', '-').rstrip('%'))
profits.update({-net_value: ["Stoploss:", stoploss_value, "Take Profit:", takeprofit_value]})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
