SeleniumJavaWebDriver:断言双引号
网站显示我需要声明的以下文本:
Living Place "123" hasn't been found
我有一个网页上的ghurkin/黄瓜,我需要断言。assertTrue使用Selenum Webdriver Java:
The text "Living Place "123" hasn't been found" is present on the page
我为此编写的java代码如下:
@Then("^The Text \"([^\"]*)\" isnt present on the page$")
public void not_present(String text) throws Throwable {
waitForTextInElementVisible(By.id("main-content"), text);
Assert.assertTrue(driver.findElement(By.id("main-content")).getText().contains(text));
}
问题是,小黄瓜脚本无法以这种方式处理字符串,因为它包含双引号。有没有一种方法可以断言上面给出的确切字符串
# 1 楼答案
我不确定我是否完全理解你的问题
但是您可以传递字符串作为“Living Place\”123\“尚未找到”。 [注意\在“内部字符串”之前]
你可以这样打电话。 不存在(“未找到居住地点\“123\”)
# 2 楼答案
试试这个
@Then("^The Text \"([^\"]*)\"\d+\"([^\"]*)\" isnt present on the page$")
。此步骤映射将映射到要素文件Then The Text "Living Place "123" hasn't been found" isnt present on the page
中的字符串。这将替换数字\“([^\“]*)\”之前的文本,即“居住地点”,这将搜索引号\“\d+\”即123中的多个数字符号,并再次搜索部分以匹配文本# 3 楼答案
显然,不是使用 \“([^\”]*)\”
我必须使用\“(.*)”
这将使小黄瓜脚本正常工作:
页面上有“居住地点”123“尚未找到”字样