0

我想检查我可以在文本字段中插入的字符数,并且正在考虑使用“for循环”,但这无济于事,因为 Selenium 尝试插入超过所需字符的字段将不接受,但测试继续没有任何失败,那么有没有办法获取文本字段的字符数?

4

2 回答 2

1

这行得通吗?

final String myLongString = "Something horrrrribly looooong";
final int longStringLength = myLongString.length();

// assuming driver is a healthy WebDriver instance
WebElement elem = driver.findElement(By.id("myInput"));
elem.sendKeys(myLongString);
// it's possible that you'll first need to lose focus on elem before the next line
int realLength = elem.getValue().length();
assertEquals(longStringLength, realLength);
于 2012-06-06T11:31:27.330 回答
0

使用量角器我捕获了该字段中的实际文本,然后进行了一个 forloop 来计算每个字母。

element(by.css('elementPATH')).getAttribute('value').then(function(words){
            //forloop to count each word
            var x = 0
            for(var i = 0; i < words.length; i++) {
                x = x + 1;
            };
            //check condition
            expect(x).toBe(200);
            return true;
        });

让我知道这是否有帮助。

于 2017-06-26T11:21:18.307 回答