【问题标题】:Why selenium webdriver can't find element为什么 selenium webdriver 找不到元素
【发布时间】:2021-12-21 10:59:04
【问题描述】:

在屏幕中你可以看到,输入的选择器只有一个。

这是代码,我在其中输入了相同的选择器,但出现如下错误:

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

代码试用:

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;
    }

【问题讨论】:

    标签: selenium selenium-webdriver xpath css-selectors invalidselectorexception


    【解决方案1】:

    你使用过的定位器:

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

    本质上是,但不是

    你需要改变:

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

    作为:

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

    【讨论】:

    • 感谢您的回答。但是 selenium 找不到这个 xpath:Find element :By.xpath: //*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')] Find element :By.xpath: //*[contains(@class,'v-label v-label--active theme--light primary--text') and contains(text(),'Narystė')]
    • @Jetz 那应该是一个不同的错误和一个不同的问题。请随时针对您的新要求提出新问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2016-09-07
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    相关资源
    最近更新 更多