0

enter image description here

element code:

<div class="col col-2"><div class="v-input v-input--is-focused theme--light v-text-field v-text-field--is-booted v-select primary--text"><div class="v-input__control"><div role="button" aria-haspopup="listbox" aria-expanded="false" aria-owns="list-65" class="v-input__slot"><div class="v-select__slot"><label for="input-65" class="v-label v-label--active theme--light primary--text" style="left: 0px; right: auto; position: absolute;">Narystė</label><div class="v-select__selections"><input id="input-65" readonly="readonly" type="text" aria-readonly="false" autocomplete="off"></div><div class="v-input__append-inner"><div class="v-input__icon v-input__icon--append"><i aria-hidden="true" class="v-icon notranslate material-icons theme--light primary--text">arrow_drop_down</i></div></div><input type="hidden" value="[object Object]"></div><div class="v-menu"><!----></div></div><div class="v-text-field__details"><div class="v-messages theme--light primary--text"><div class="v-messages__wrapper"></div></div></div></div></div></div>

in screen you can see, that entered xpath is only one.

Here is code, where i have entered the same xpath, but getting error like this:

 private static final By naryste = By.xpath("//*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]");
    @Step("Pasirenkame juridinio asmens organizaciją iš reikšmių sąrašo")
    public createOrganization selectMembership() {
        button.click(naryste);
        return this;
    }

Selenium webdriver can't find this xpath:

Find element :By.xpath: //*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]

P.S. the same problem if i choose other elements enter image description here

AND this (selenium can't find)

enter image description here

Jetz
  • 207
  • 2
  • 4
  • 14
  • Instead of an image can you update the question with the text based HTML of the element? – undetected Selenium Nov 08 '21 at 17:26
  • i have added element code, idk if it helps you, code is inline.. – Jetz Nov 08 '21 at 17:39
  • Refers to a _`readonly`_ element, are you sure the element is interactable? – undetected Selenium Nov 08 '21 at 17:43
  • css classes aren't always unique... I'd just use the text()= part there. (Unless something else on the page is labeled "Narystė". Still you'd want to target something besides the label. Maybe use //div[@aria-owns="list-65"] or //input[@id="input-65"] ? depends on what takes the click event? (Not sure what button.click() method is in your code...) – pcalkins Nov 08 '21 at 18:29
  • @pcalkins, id input-XX is generate dinamically after refresh. – Jetz Nov 08 '21 at 18:38
  • @DebanjanB, i'm not sure, maybe i should choose other element in this div and i tryied, but result is the same. I – Jetz Nov 08 '21 at 18:40
  • You need to use a webdriverwait for any JS added components: https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/WebDriverWait.html – pcalkins Nov 08 '21 at 18:41

1 Answers1

0

To locate the element you can use the following Locator Strategy:

  • Using xpath:

    By.xpath("//label[starts-with(@for,'input') and contains(.,'Narystė')]");
    

PS: Do add some waits before invoking the click()

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352