Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send keys to an element with type = number using Selenium Python?

I am trying to send a number to an element (a textbox) that only takes number values. This element is as follows:

Currently, I have this code (the code under this paragraph) to input a number into the element. Could anyone tell me why the number isn't showing up? Any help would be appreciated.

bpm = 121
inputBpm = driver.find_element(By.XPATH, "/html/body/mp-root/div/ ... /div[3]/div/input")
inputBpm.clear()
inputBpm.send_keys(str(bpm))

Edit: Here's a visual of what I'm trying to type into (after it's been cleared) The textbox

Here's the surrounding element:

<div _ngcontent-soo-c572="" class="track-bpm">
<label _ngcontent-soo-c572="" class="input-title">BPM</label>
<span _ngcontent-soo-c572="" class="input-title-info">(Beats per minute)</span>
<div _ngcontent-soo-c572="" class="input-text">
<input _ngcontent-soo-c572="" type="number" name="bpm" placeholder="0" min="0" max="999" step="0.01" class="ng-pristine ng-valid ng-touched"></div>
</div>
like image 855
THEMOUNTAINSANDTHESKIES Avatar asked Aug 23 '26 12:08

THEMOUNTAINSANDTHESKIES


1 Answers

You can simply do,

if inputBpm.get_attribute("type")  == "number":
    inputBpm.clear()
    inputBpm.send_keys(str(bpm))

Or you can just find that input tag with type = number using XPATH.

input_tag = driver.find_element(By.XPATH, "//input[contains(@type, 'number')]")
inputBpm.clear()
input_tag.send_keys("9023")
like image 126
Zero Avatar answered Aug 25 '26 01:08

Zero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!