Reputation: 23
I have an array 'sale_prices' that contains item prices. I also have an equal amount of input forms. I am trying to loop through each sale price and add it to the corresponding input so that input_box[1] == sale_price[1] etc... Right now my code inputs every sale price into each input form
sale_prices = [
'199.99',
'199.99',
'169.99',
'217.99',
'210.99',
'227.99',
'230.99',
'257.99',
'265.99',
'271.99',
]
def add_prices():
sale_id = '98603'
driver.get('https://www.#######/sale-pricing.php?sale={}'.format(sale_id))
check_boxes = driver.find_elements_by_class_name('sale_checked')
input_boxes = driver.find_elements_by_xpath('//*[contains(@id, "price_")]')
for check_box in check_boxes:
check_box.click()
for sale_price in sale_prices:
for input_box in input_boxes:
input_box.send_keys(sale_price)
Upvotes: 0
Views: 100
Reputation: 466
Change the for loop to this and it should work.
for i in range(len(sale_prices)):
input_boxes[i].send_keys(sales_prices[i])
You are looping every value on input box.
Upvotes: 2