1

I'm using selenium chromedriver to automate the filling in of a form. the last step is copying the final price. when i try to get text from the element i receive nothing.

Below is a picture of the element in question. i want to pull a price from it.

picture of problem 1: https://i.stack.imgur.com/V6T1k.png

This element is really big with so many attributes im not sure how to start

<input id="TotalRegularPayment" name="TotalRegularPayment" sr-money-focus-clear="" sr-money-value="" class="mousetrap form-control ng-pristine ng-untouched ng-valid ng-not-empty" tabindex="1" type="text" ng-model="$ctrl.field.value" ng-change="$ctrl.onChange()" ng-disabled="($ctrl.field.meta.is_read_only || $ctrl.isLockedDown)" disabled="disabled">

These lines:

print("read this")
print("---")
print(totalprice.text)    
print("---")
print(totalprice.get_attribute('innerHTML'))
print("---")
print(pricewrapper.text)
print("---")
print(pricewrapper.get_attribute('innerHTML'))

gives this output:

read this
---

---

---
Total Rental
£
excl. VAT
---
 <div class="col-sm-4 label-col"> <label for="TotalRegularPayment" class="ng-binding">Total Rental</label> </div> <div class="col-xs-10 col-sm-6 input-col"> <div class="input-group currency"> <span class="input-group-addon calculator-addon disabled-style" ng-class="{'disabled-style': ($ctrl.field.meta.is_read_only || $ctrl.isLockedDown)}"><currency-symbol class="ng-isolate-scope"><span class="ng-binding">£</span></currency-symbol></span> <input id="TotalRegularPayment" name="TotalRegularPayment" sr-money-focus-clear="" sr-money-value="" class="mousetrap form-control ng-pristine ng-untouched ng-valid ng-not-empty" tabindex="1" type="text" ng-model="$ctrl.field.value" ng-change="$ctrl.onChange()" ng-disabled="($ctrl.field.meta.is_read_only || $ctrl.isLockedDown)" disabled="disabled"> <!-- ngIf: $ctrl.field.meta.show_vat_label --><span class="input-group-addon vat-placeholder ng-binding ng-scope disabled-style" ng-if="$ctrl.field.meta.show_vat_label" ng-class="{'disabled-style': ($ctrl.field.meta.is_read_only || $ctrl.isLockedDown)}"> excl. VAT </span><!-- end ngIf: $ctrl.field.meta.show_vat_label --> </div> </div> <div class="col-xs-2 col-sm-2 text-center"> <sr-calculating-spinner field="$ctrl.field" calculator-id="$ctrl.calculatorId" on-calculate="$ctrl.calculate()" class="ng-isolate-scope"><!-- ngIf: $ctrl.field.meta.is_calculable && !$ctrl.quoteModel.is_quote_read_only --> <!-- ngIf: $ctrl.model.calculation_path === $ctrl.field.meta.name && $ctrl.model.is_calculating --></sr-calculating-spinner> </div> 

The element i want is total price but i also printed its wrapper to see if i got anything useful i didnt. could you please advise on how i could print the price.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Are you using xpath to find the element. can you post that code? I also don't see the actual price in the element. Are you looking at a different element – Sureshmani Kalirajan Jul 10 '20 at 17:09

1 Answers1

0

To print the value within the <input> tag i.e. 355.60 as the element is Angular element you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input#TotalRegularPayment[name='TotalRegularPayment']"))).get_attribute("value"))
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='TotalRegularPayment' and @name='TotalRegularPayment']"))).get_attribute("value"))
    
  • 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