Can't set value by input index

Can someone help me change the value of my input.
The problem is that I have several inputs with the same CssSelector:

input.ng-pristine.ng-untouched.ng-valid.ng-not-empty.ng-valid-required.ng-valid-pattern.ng-valid-maxlength

so I would like to be able to choose them by index and selenium, but …

Can you direct me to get there please

hi,

Sorry not read clearly your issue :slight_smile:
you have already used CSS Selectors

try to use CSS Selector as locator
in browser
inspect → copy → CSS Selector

and use javascript
String js = ‘document.querySelector(“#my-button”).click();’
WebUI.executeJavaScript(js, null)
some info will found here

1 Like

hi,

what about javascript document.getElementsByClassName(“class-name”)[0].click()

getElementsByClassName will return list so you can try to search your inputs as index

2 Likes

You can either locate all of the inputs and gather them into a list, then access each input by giving an index to that list (pseudocode):

List<WebElement> inputs = ... // locate all <input> elements
inputs.get(0).sendKeys(...)
inputs.get(1).sendKeys(...)
.
.
.
inputs.get(n).sendKeys(...)

… or you can provide an index in your locator that will return ONLY the element at a given index (pseudocode):

WebElement input = ... // include desired index in whichever locator you are using
input.sendKeys(...)
1 Like

Thank you very much Brandon

:smiley:

I were to use the WebElment list and its index.