Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 当预期消息的mora超过一行时,量角器ExpectedConditions.TextToBePresentElement返回false_Selenium_Protractor - Fatal编程技术网

Selenium 当预期消息的mora超过一行时,量角器ExpectedConditions.TextToBePresentElement返回false

Selenium 当预期消息的mora超过一行时,量角器ExpectedConditions.TextToBePresentElement返回false,selenium,protractor,Selenium,Protractor,我面临量角器的新问题, 当我尝试使用此selenium方法时: ExpectedConditions.TextToBePresentElement 它返回false,因为my元素返回以下消息: 连接不可用。 此时无法连接到设备 这是我期望的字符串: 消息:连接不可用。\n此时无法连接到设备 那么我的方法调用是: browser.wait(ExpectedConditions.textToBePresentInElement(element, message), 160000, 'The expe

我面临量角器的新问题, 当我尝试使用此selenium方法时:

ExpectedConditions.TextToBePresentElement

它返回false,因为my元素返回以下消息: 连接不可用。 此时无法连接到设备

这是我期望的字符串:

消息:连接不可用。\n此时无法连接到设备

那么我的方法调用是:

browser.wait(ExpectedConditions.textToBePresentInElement(element, message), 160000, 'The expected text is not present in the UI');

也许有人能帮我解决这个问题

也许这不是最好的方法,但它会解决你的问题。只需将预期消息替换为没有
\n
的消息即可:

browser.wait(ExpectedConditions.textToBePresentInElement(element, message.replaceAll("\\n", " ")), 
             160000, 'The expected text is not present in the UI');

这实际上是最好的办法;另一种方法是搜索文本中需要的关键字,如“连接不可用”,然后假设消息的其余部分是正确的,或者搜索“设备”。但是这些需要不同的匹配器,而不是另一台macthers的
texttobepresentElement
?你能给我举个例子吗?谢谢