SeleniumJavaWebDriver:断言双引号

SeleniumJavaWebDriver:断言双引号,java,selenium,webdriver,cucumber,gherkin,Java,Selenium,Webdriver,Cucumber,Gherkin,网站显示我需要声明的以下文本: Living Place "123" hasn't been found 我在网页上有一块ghurkin/cucumber,我需要使用Selenum Webdriver Java断言.assertTrue: The text "Living Place "123" hasn't been found" is present on the page 我为此编写的java代码如下: @Then("^The Text \"([^\"]*)\" isnt pr

网站显示我需要声明的以下文本:

Living Place "123" hasn't been found
我在网页上有一块ghurkin/cucumber,我需要使用Selenum Webdriver Java断言.assertTrue:

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));
}

问题是,小黄瓜脚本无法以这种方式处理字符串,因为它包含双引号。是否有一种方法可以断言上面给出的确切字符串?

我不确定是否完全理解您的问题

但是您可以传递字符串作为“Living Place\”123\“尚未找到”。 [注意\在“内部字符串”之前]

你可以这样打电话。
不存在(“Living Place”123“尚未找到”);

尝试这一个
@然后(“^The Text\”([^\“]*)\”)“\d+\”([^\“]*)\“在页面$”上不存在”
。此步骤映射将映射到功能文件
中的字符串,然后未找到文本“Living Place”123“不在页面上
。这将替换数字\“([^\“]*)\”之前的文本,即“居住地点”,这将搜索引号\“\d+\”即123中的多个数字符号,并再次部分匹配文本。

显然,不是使用 \“([^\”]*)\”

我必须使用\“(.*)”

这将使小黄瓜脚本正常工作:


页面上有“Living Place”123“尚未找到”的文字

你能再解释一下你的答案吗?我想我知道你在说什么,但不太管用\“([^\“]*)\”是我们在这里使用的标准字符串,但它需要更改,但我不知道是什么