Home > Software design >  How to get list of inputs using find element in Selenium
How to get list of inputs using find element in Selenium

Time:02-04

I'm trying to enter OTP in the browser it has 5 inputs each input for the latter. If I enter code manually it behaves like after clicking its jumps to the next input but in Selenium, it stays on one input and tries to enter code in the first input box.

   input = browser.find_element(
        By.XPATH, "//form//input[@type='text']").send_keys("123456")

I want to get all inputs in the list and then enter OTP on each box by the loop.

CodePudding user response:

Try getting the elements with:

inputs = browser.find_elements(By.XPATH, "//form//input[@type='text']")

and then iterate over them:

for element in inputs:
    element.send_keys("some_string\n")

CodePudding user response:

To get all inputs in the list and then enter OTP on each box by the loop you need to use find_elements() to make a list of the <input> elements as follows:

input_elements = browser.find_elements(By.XPATH, "//form//input[@type='text']")
for input_element in input_elements:
    input_element.send_keys("123456")
  • Related