amstriker
amstriker

Reputation: 389

Need to Select dropdown via selenium javascript

I have drop down code the following below.

<div class="w-1/2 px-8 pt-6">
<div class="Styled__FieldWrapper-sc-1fqfnqk-1 bQZNMa mb-6">
    <label class="form-label" for="transfer.account">Transfer Account</label>
        <div class=" css-2b097c-container">
            <span aria-live="polite" aria-atomic="false" aria-relevant="additions text" class="css-7pg0cj-a11yText"></span>
                <div class=" css-yk16xz-control">
                    <div class=" css-1hwfws3">
                        <div class=" css-1uccc91-singleValue"></div>
                        <div class="css-1g6gooi">
                            <div class="" style="display: inline-block;">
                                <input autocapitalize="none" autocomplete="off" autocorrect="off" id="react-select-2-input" spellcheck="false" tabindex="0" type="text" aria-autocomplete="list" value="" style="box-sizing: content-box; width: 2px; background: 0px center; border: 0px; font-size: inherit; opacity: 1; outline: 0px; padding: 0px; color: inherit;" class="">
                                    <div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 15px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;"></div>
                            </div>
                        </div>
                    </div>
                    <div class=" css-1wy0on6">
                        <div class=" css-tlfecz-indicatorContainer" aria-hidden="true">
                            <svg height="20" width="20" viewBox="0 0 20 20" aria-hidden="true" focusable="false" class="css-8mmkcg"><path d="M14.348 14.849c-0.469 0.469-1.229 0.469-1.697 0l-2.651-3.030-2.651 3.029c-0.469 0.469-1.229 0.469-1.697 0-0.469-0.469-0.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-0.469-0.469-0.469-1.228 0-1.697s1.228-0.469 1.697 0l2.652 3.031 2.651-3.031c0.469-0.469 1.228-0.469 1.697 0s0.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c0.469 0.469 0.469 1.229 0 1.698z"></path></svg>
                        </div>
                        <span class=" css-1okebmr-indicatorSeparator"></span>
                        <div class=" css-tlfecz-indicatorContainer" aria-hidden="true">
                            <svg height="20" width="20" viewBox="0 0 20 20" aria-hidden="true" focusable="false" class="css-8mmkcg">
                                <path d="M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z"></path></svg>
                        </div>
                    </div>
                </div>
                <input name="transfer.account" type="hidden" value="">
        </div>
</div>

I have used the following below:

  By.xpath("//input[@id='react-select-15-input']")).click(); 
  or
  By.id( "react-select-15-input")).sendKeys("David Messi");

But no luck. I want to select drop down vai selenium, Any help?

Upvotes: 0

Views: 177

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

I am not sure if you already have some some framework in place,

Cause this looks wrong :

By.path("//input[@id='react-select-15-input']")).click(); 

is should be xpath instead of path.

By.xpath("//input[@id='react-select-15-input']")).click(); 

or

You can try this in Javascript :

driver.click('drop down locator here').click('drop down value locator here')

Upvotes: 1

Related Questions