1
    mins = WebDriverWait(browser, 30).until(EC.visibility_of_element_located((By.NAME, "yt_min")))
    browser.execute_script("arguments[0].setAttribute('value', '20');", mins)

I want it to change it to a random number in a specific range instead of 20, I know the randint method but I don't know how to approach it since it's a string

2
  • 1
    I'm not familiar with Selenium, but I guess that you're looking for string interpolation: "arguments[0].setAttribute('value', '{}');".format(randint(1, 100)) (or whatever range you want) Commented Oct 20, 2020 at 2:24
  • You generate a random number and convert to a string. Where are you stuck on this? Commented Oct 20, 2020 at 2:54

1 Answer 1

1
import random

A = random.randint(range here)

mins = WebDriverWait(browser,  30).until(EC.visibility_of_element_located((By.NAME, "yt_min")))
browser.execute_script("arguments[0].setAttribute('value', f'{str(A)}');", mins)
Sign up to request clarification or add additional context in comments.

2 Comments

You can do this
Message: javascript error: missing ) after argument list I am getting this error

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.