Home > Mobile >  Selenium send_keys does not send comma
Selenium send_keys does not send comma

Time:12-30

I try to use send keys like this

price = driver.find_element(By.XPATH,'//*[@id="contentproform-ppv_cost"]')
price.clear()
price.send_keys("12,99")

Which only results in sending 1299. I tried to paste it from the keyboard with the same result. What am I doing wrong?

CodePudding user response:

This is less about Selenium and more about currency conversion in different countries. That website has JS that prevents invalid input for currency. There's a dot separator that's probably different from the country you're in. Here's the info from the web:

"United States (U.S.) currency is formatted with a decimal point (.) as a separator between the dollars and cents. Some countries use a comma (,) instead of a decimal to indicate that separation. In addition, while the U.S. and a number of other countries use a comma to separate thousands, some countries use a decimal point for this purpose."

I took a screenshot from Google. The full info was on the Cornell University site:

CodePudding user response:

You have two choices, either send as 12.99 or use the following code:

price = driver.find_element(By.XPATH,'//*[@id="contentproform-ppv_cost"]')
price.clear()
price.send_keys("12")
price.send_keys(Keys.COMMA)
price.send_keys("99")

As there is no website to test against, it is unclear whether this technique will work.

The send_keys method is sending the string as text, so it is possible that the comma is being interpreted as a character and not as a decimal separator.

  • Related