Rayrun
← Back to Discord Forum

dom

sebitas1340posted in #help-playwright
Open in Discord
sebitas1340
sebitas1340

hello all, again here. I need some help 😦

From the DOM, I have this div element with 6 input elements having the class. I want to use Playwright and Python to access each of these elements and place a specific value in each input of the div.

<div class="OTPForm_otpForm__uLxqO"><input class="OTPForm_input__n25Kb " placeholder="-" type="number" value="2"><input class="OTPForm_input__n25Kb " placeholder="-" type="number" value=""><input class="OTPForm_input__n25Kb " placeholder="-" type="number" value=""><input class="OTPForm_input__n25Kb " placeholder="-" type="number" value=""><input class="OTPForm_input__n25Kb " placeholder="-" type="number" value=""><input class="OTPForm_input__n25Kb " placeholder="-" type="number" value=""></div>

I already provided this code, and I want to be able to iterate over each element to place the corresponding value in each one. However, it's not working as expected, as I see the cursor moving over each element, but it doesn't place the value "1" in the input with class at position 0, "2" in the input with class at position 1, and so on. I want to correct this so that it works as intended.

Here is a snippet of my function's code: # Get the div and input elements # div_element = page.query_selector(".OTPForm_otpForm__uLxqO") input_elements = page.query_selector_all(".OTPForm_otpForm__uLxqO input.OTPForm_input__n25Kb")

# Values I want to fill in the input fields
valores_a_completar = ["1", "2", "3", "4", "5", "6"]

# Fill each element with the corresponding value
for input_element, valor in zip(input_elements, valores_a_completar):
    # Simulate input event before filling the value
    input_element.dispatch_event("input")
    input_element.fill(valor)

thanks in advance

Captura_de_pantalla_2023-08-01_a_las_11.43.57.png

This thread is trying to answer question "How can I use Playwright and Python to access each input element in a div from the DOM and place a specific value in each input?"

3 replies
sebitas1340
sebitas1340

this is actual result

Captura_de_pantalla_2023-08-01_a_las_12.58.31.png
sebitas1340
sebitas1340

And, this is the pretty code snippet that I am using

Captura_de_pantalla_2023-08-01_a_las_12.59.47.png

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.