Home > Back-end >  Why selenium webdriver can't find element
Why selenium webdriver can't find element

Time:11-09

enter image description here

In screen you can see, that entered selector is only one.

Here is code, where I have entered the same selector, but getting error like this:

Element info: {Using=css selector, value=//*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]}
Find element :By.cssSelector: //*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]
Get Exception: invalid selector: An invalid or illegal selector was specified

Code trils:

private static final By naryste = By.cssSelector("//*[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;
    }

CodePudding user response:

The locator you have used:

//*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]

is essentially an but not a

You need to change:

By.cssSelector("//*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]");

As:

By.xpath("//*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]");
  • Related