首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse中的Junit不能处理LinkText撇号

Eclipse中的Junit不能处理LinkText撇号
EN

Stack Overflow用户
提问于 2013-08-13 10:50:19
回答 1查看 473关注 0票数 1

测试用例在Selenium IDE中运行,但是在导出到WebDriver并在Eclipse中执行时,Junit脚本无法找到名称中带有撇号的LinkText元素。

我转义了撇号,但Junit仍然找不到它。

有问题的行将在代码中突出显示

我导出了一个不包含任何撇号的Selenuim测试用例,并且能够在WebDriver中运行Eclipse测试,没有任何问题。

我将继续使用没有撇号的测试用例,但如果我能弄清楚如何处理特殊字符,那就太好了。

由衷地,

里克·杜塞特

代码语言:javascript
复制
 import java.util.regex.Pattern;
    import java.util.concurrent.TimeUnit;
    import org.junit.*;
    import static org.junit.Assert.*;
    import static org.hamcrest.CoreMatchers.*;
    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.Select;

    public class FirstSelIDEDemo {
      private WebDriver driver;
      private String baseUrl;
      private boolean acceptNextAlert = true;
      private StringBuffer verificationErrors = new StringBuffer();

      @Before
      public void setUp() throws Exception {
        driver = new FirefoxDriver();
        baseUrl = "http://www.soastastore.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

      @Test
      public void testFirstSelIDEDemo() throws Exception {
        driver.get(baseUrl + "/");
        driver.findElement(By.linkText("Store")).click();
        driver.findElement(By.linkText("Tron: Legacy")).click();
        driver.findElement(By.id("product_155_submit_button")).click();
        new Select(driver.findElement(By.name("product_rating"))).selectByVisibleText("2");
        driver.findElement(By.id("s")).clear();
        driver.findElement(By.id("s")).sendKeys("firth");
        driver.findElement(By.id("searchsubmit")).click();
        *****driver.findElement(By.linkText("The King\'s Speech")).click();*****
        driver.findElement(By.name("product_rating")).click();
        new Select(driver.findElement(By.name("product_rating"))).selectByVisibleText("4");
        driver.findElement(By.cssSelector("form.wpsc_product_rating > input[type=\"submit  \"]")).click();
        driver.findElement(By.id("product_160_submit_button")).click();
        new Select(driver.findElement(By.name("product_rating"))).selectByVisibleText("4");
        driver.findElement(By.cssSelector("form.wpsc_product_rating > input[type=\"submit\"]")).click();
        driver.findElement(By.id("product_160_submit_button")).click();
        driver.findElement(By.linkText("Checkout")).click();
        driver.findElement(By.cssSelector("form.adjustform.remove > input[name=\"submit\"]")).click();
        driver.findElement(By.cssSelector("span > input[name=\"submit\"]")).click();
        // Warning: assertTextPresent may require manual changes
        assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*ERROR: Please enter a username\\.[\\s\\S]*$"));
  }

  @After
      public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
    }
  }
EN

回答 1

Stack Overflow用户

发布于 2013-08-13 16:18:39

您不需要在Java源代码中转义撇号,因此您可能会丢失\。你生成的超文本标记语言有效吗(如果它在一个属性中,那么它的源代码中应该有' )?也许它实际上不是' (代码为u+0027),而是其他类似u+2019 (http://www.fileformat.info/info/unicode/char/2019/index.htm)的东西?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18199871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档