0

I was wondering how to use python to change an element in a page's HTML code:

Specifically, from:

<input _ngcontent-mcp-c552="" type="number" name="bpm" placeholder="0" min="0" max="999" step="0.01" class="ng-valid ng-dirty ng-touched">

to

<input _ngcontent-mcp-c552="" type="number" name="bpm" placeholder="0" min="0" max="999" step="1" class="ng-valid ng-dirty ng-touched">

(Changing the step-size value)

The HTML I'm attempting to edit would not be of my own HTML file, but a public website. As such, the change would only be temporary; but I'm okay with that. Any help would be greatly appreciated. Thank you.

CONTEXT: Using automation, I'm trying to input a value (a number) into a textbox; but for some reason the send_keys function from selenium isn't sending any keys. So, I found that I could just select the element and hold the up arrow key until I attain the value I'd like. Problem is, the element's current step-size of 0.01 makes attaining the values I want (varying between 60-180) take very long. And now that's the problem I'm trying to sort out now.

1 Answers1

0

To change the attribute from:

step="0.01"

to:

step="1"

you need to use setAttribute() as follows:

my_element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='ng-valid ng-dirty ng-touched' and @name='bpm'][@type='number']")))
driver.execute_script("arguments[0].setAttribute('step','1')", my_element)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • When I do that, the my_element = WebDriver... line causes a TimeoutException Error – what could be causing that? – THEMOUNTAINSANDTHESKIES May 04 '22 at 22:43
  • _TimeoutException Error_ as the [_locator strategy_](https://stackoverflow.com/questions/48054321/of-the-many-findelements-by-functions-in-selenium-when-would-you-use-one-over) doesn't finds the element due to some reason. Check [this discussion](https://stackoverflow.com/a/47995294/7429447) – undetected Selenium May 04 '22 at 22:47