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 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

When I do that, the my_element = WebDriver... line causes a TimeoutException Error – what could be causing that?
TimeoutException Error as the locator strategy doesn't finds the element due to some reason. Check this discussion

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.