找到包含值的一部分的所有xpath属性

时间:2017-04-21 11:40:26

标签: selenium xpath

我需要等待包含单词“mask”的属性“id”无法显示所有元素。我试过这样的:

//*[contains(@id *= 'mask')]

然而它给了我一个未找到的元素。

2 个答案:

答案 0 :(得分:0)

在这种情况下,您可以使用显式等待,如下所示。

WebDriverWait wait = new WebDriverWait(driver,15);
        wait.until(ExpectedConditions.invisibilityOfAllElements(driver.findElements(By.xpath("//*[starts-with(@id,'mask')]"))));

在c#中,他们没有实现此方法,但您可以实现它。

以下是可以帮助您撰写的网址。

https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/support/UI/ExpectedConditions.cs#L140

答案 1 :(得分:0)

我相信您正在寻找的语法是:

//*[contains(@id,'mask')]

我做了类似的事情,我等到包含" BlockUI"

的类的计数为零
public static void waitForBlockUIToDisappear() {
        // This function checks the entire currently-loaded web page for the
        // presence of any web element of the
        // class "blockUI" and loops until there are none. The presence of an
        // element with this class does exactly
        // what it implies: it blocks user input. If you get the error that a
        // different web element would receive
        // the click, for example, this is why and you'd need to call this
        // method before doing a click. Generally,
        // this function should be implemented before sending any input to a web
        // page - click, sendkeys, select...
        String blockUI = "//*[contains(@class,'blockUI')]";
        while (true) {
            if (driver.findElements(By.xpath(blockUI)).size() == 0)
                break;
        }
        ;
    }

您应该能够更改该代码,以查找您的ID以包含您的文字。