gpt4 book ai didi

Selenium:文本的一部分

转载 作者:行者123 更新时间:2023-12-04 06:20:55 24 4
gpt4 key购买 nike

有没有办法只验证存在的部分文本?

如果有文本“警告:A15P09 尚未激活。”我需要验证文本是否存在。但是,“A15P09”并不总是相同的,所以我不能做类似的事情

Selenium.IsTextPresent("Warning: A15P09 has not been activated.");

我可能会做这样的事情:
Selenium.IsTextPresent("has not been activated.");

但是有没有另一种方法可以在 Selenium 中验证这一点。如果有,请告诉我。

谢谢!

最佳答案

您可以使用 getText然后执行您的语言提供的任何正常正则表达式来检查该结果。
编辑:对于某些语言,您可以这样做 isTextPresent在模式修改的字符串上。该文件指出:

Various Pattern syntaxes are availablefor matching string values:

glob:pattern: Match a string against a"glob" (aka "wildmat") pattern. "Glob"is a kind of limitedregular-expression syntax typicallyused in command-line shells. In a globpattern, "*" represents any sequenceof characters, and "?" represents anysingle character. Glob patterns matchagainst the entire string.

regexp:regexp: Match a string using aregular-expression. The full power ofJavaScript regular-expressions isavailable.

exact:string: Match astring exactly, verbatim, without anyof that fancy wildcard stuff.

If nopattern prefix is specified, Seleniumassumes that it's a "glob" pattern.

关于Selenium:文本的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6584287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com