0

I am stuck on how to enter the input value selecting a building. Initially, there will be only two empty input fields for selecting a building, as you enter one it will add an empty input field. I don't see any indexing on how to select and enter the building names one by one without overwriting them, the building values are
buil= ["HillsDale","astoria","Franklin",....]
here is what the HTML looks like

 <li class="checkout-order-summary-list-added-item js-checkout-added-item" data-json-object- 
   name="Building">
    <div class="row">
        <div class="item-valid-icon hidden">
            <span class="glyphicon glyphicon-ok"></span>
        </div>
        <div class="col-xs-7 col-sm-7 col-md-6">
            <div class="form-group js-sku-container">
                
                <label class="control-label ">Building NO</label>
                <input class="text form-control js-checkout-field-validation js-checkout-json-object-field js-sku-input-field generic-js-site-search-input ui-autocomplete-input" type="text" name="BuildingsSKU" data-validation-reason="Buildings are added to order." data-json-object-name="Buildings" data-update-targets=".subtotals-parts,.subtotals" >
                <input type="hidden" class="js-hidden-sku-field" value=" ">
                <div class="js-validation-container help-block"></div>
            </div>
        </div>
        <div class="col-xs-5 col-sm-5 col-md-2">
            <div class="form-group">
                <label class="control-label">Qty</label>       
    
<input type="number" min="1" max="999" data-range-validation-error-msg="Value should be in range from 1 to 999" value="1" data-toggle="tooltip" qty="" name="quantity" class="text form-control js-checkout-json-object-field js-checkout-qty ">
            </div>
        </div>
    </div>
</li>
<li class="checkout-order-summary-list-added-item js-checkout-added-item" data-json-object-name="Building">
    <div class="row">
        <div class="item-valid-icon hidden">
            <span class="glyphicon glyphicon-ok"></span>
        </div>
        <div class="col-xs-7 col-sm-7 col-md-6">
            <div class="form-group js-sku-container">
                
                <label class="control-label ">Building NO</label>
                <input class="text form-control js-checkout-field-validation js-checkout-json-object-field js-sku-input-field generic-js-site-search-input" type="text" name="BuildingsSKU" data-validation-reason="Buildings were added to order." data-json-object-name="Buildings" data-update-targets=".subtotals-parts,.subtotals" >
                <input type="hidden" class="js-hidden-sku-field" value=" ">
                <div class="js-validation-container help-block"></div>
            </div>
        </div>
        <div class="col-xs-5 col-sm-5 col-md-2">
            <div class="form-group">
       

     <label class="control-label ">Qty</label>

and this is what the form looks like

enter image description here


Any help really be appreciated. so far I have tried
driver.find_element_by_xpath("//div[contains(@class,'text form-control js-checkout-field-validation')]").send_keys(buil[0])

2
  • try getting a list of all text inputs, and then put your next buildingName to be inputted into the LAST txt input field. wait, then get all input fields again. since you keep inputting into the last, and each input causes another field to appear, you'll end up with an empty first field and filled the rest
    – smcrowley
    Jul 15, 2022 at 18:26
  • or you can loop through all the buildingNames you want to enter, and for each of them get a list of all the input fields on the page. then you can enter your building name into the input who's index in the list matches the buildingNames index
    – smcrowley
    Jul 15, 2022 at 18:27

2 Answers 2

0

Something to try. Get all building inputs and index them to send text:

fields = driver.find_elements_by_xpath("//div[contains(@class,'text form-control js-checkout-field-validation')]")
    
    fields[0].send_keys(buil[0])
    fields[1].send_keys(buil[1])

Or you can just use xpath directly:

driver.find_element_by_xpath("(//div[contains(@class,'text form-control js-checkout-field-validation')])[1]").send_keys(buil[0])

driver.find_element_by_xpath("(//div[contains(@class,'text form-control js-checkout-field-validation')])[2]").send_keys(buil[1])

I can't say if this is the correct xpath since I don't have the url but it should be close.

0
0
for x in buil:
   driver.find_elements(By.XPATH,"//input[@class='text form-control js-checkout-field-validation js-checkout-json-object-field js-sku-input-field generic-js-site-search-input']")[-1].send_keys(k)

Could always just find elements and access the last 1 with -1 in Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.