简体   繁体   English

如何验证 selenium IDE 中是否存在任何文本

[英]How to verify ANY text is present with selenium IDE

I know how to verify if a specific text is present in a web page using Selenium IDE.我知道如何使用 Selenium IDE 验证网页中是否存在特定文本。 But what I wanted to know is, can you verify that any text is present in an element?但是我想知道的是,您能否验证元素中是否存在任何文本?

For example there's a text box with the title "Top Champion".例如,有一个标题为“顶级冠军”的文本框。 This text box will be changed daily with the name of a person.此文本框将每天更改为人名。 Now I just wanted to check whether there is a text in this text box, no matter what the text actually is.现在我只想检查这个文本框中是否有文本,不管文本实际上是什么。 I've tried the verify text command and tried blanking the value, but it doesn't work.我试过验证文本命令并尝试将值清空,但它不起作用。 If the command can return a true or false command that would be really helpful如果命令可以返回一个真正有用的真或假命令

BTW, verify value doesn't work either since the element that I'm testing is not a form field顺便说一句,验证值也不起作用,因为我正在测试的元素不是表单字段

Your best bet is as follows (I have written single tests for this for numbers) 最好的选择是如下(我为此编写了单项测试数字)

Medium rigour: 中度:

waitForText | css=.SELECTORS | regex:.+?

This will wait until there is at least 1 character present. 这将等待,直到至少存在1个字符为止。

Strong rigour (only works if you have a subset of characters present): 严格要求严格(仅在存在一部分字符的情况下有效):

waitForText | css=.SELECTORS | regex:^[0-9]+$

This will wait until there is text. 这将等待直到有文本。 This text must start with a number, have at least 1 number, and then finish. 该文本必须以数字开头,至少具有1个数字,然后再结束。 It does not permit any character outside of the subset given. 它不允许给定子集之外的任何字符。 An example you could do to match numbersNAMEnumbers would be. 您可以做一个匹配数字NAME数字的示例。

waitForText | css=.SELECTORS | regex:^[0-9]+[a-zA-Z]+[0-9]+$

This would wait for a string such as 253432234BobbySmith332 这将等待诸如253432234BobbySmith332之类的字符串

Luke 卢克

If i have understood your question properly there below is one way you can search for an element contains a string. 如果我正确地理解了您的问题,则下面是一种可以搜索包含字符串的元素的方法。 Not sure if this is what you are looking. 不知道这是您在找什么。

List<WebElement> findElement = webElement.findElements(By.xpath("YOUR_TEXTINPUT_PATH_HERE"));
     if( findElement.size() > 0 ){
          if( findElement.get(0).getText() != null &&   findElement.get(0).getText().indexOf("THE_STRING_THAT_YOU_WANT_TO SEARCH") != -1 ) {
              // IF IT COMES HERE, THAT MEANS THE ELEMENT IS PRESENT WITH THE TEXT
          }
     }
store text|[your element]|StoredText  
execute script|return ${StoredText}.length > 0|x  
assert|x|true  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM