0

I have a form such as this:

enter image description here

I am trying to set the input field value to a postal code value "M3C1B4" and then I would like to click the button.

Although I can click the button I am unable to set the value of the input field.

I've tried the following code with no success:

driver.execute_script('arguments[0].value = "M3C1B4";', driver.find_element_by_xpath('//div[@class="shippingBox-update"]//input'))
driver.find_element_by_xpath('//div[@class="shippingBox-update"]//input').send_keys('M3C1B4')

Clicking the button works using this code:

driver.find_element_by_xpath('//div[@class="shippingBox-update"]//button').click()

2 Answers 2

1

You are using _ instead of - in "shippingBox_update". Should be

driver.find_element_by_xpath('//div[@class="shippingBox-update"]//input').send_keys('M3C1B4')

By the way, why don't you use the <input> class?

driver.find_element_by_class_name("PC_change_input").send_keys('M3C1B4')
driver.find_element_by_class_name("button-submit").click()
Sign up to request clarification or add additional context in comments.

3 Comments

Actually you are right I did use a _ instead of a -. However, it still doesn't work.
I got it to work actually. Because of your tip, I fixed my error and then I saw that the textbox was being interacted with but it was already populated with a default value which had to be cleared. When I cleared it, the box is now being populated properly!
you're right I should just use the input class but I'll optimize the code at a later time. Right now just want to quickly prototype.
1

Sorry for the trouble. I got it to work. Apart from the error where I had _ instead of - that was pointed out by "guy", there was another problem.

The box was populated by a default value that had to be cleared first because the box only allowed for 6 values.

This did the trick:

driver.find_element_by_xpath('//div[@class="shippingBox-update"]//input').clear()
driver.find_element_by_xpath('//div[@class="shippingBox-update"]//input').send_keys('M3C1B6')
driver.find_element_by_xpath('//div[@class="shippingBox-update"]//button').click()

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.