【问题标题】:Hello, I have a problem with my code in Eclipse for Selenium testing [duplicate]您好,我在 Eclipse 中用于 Selenium 测试的代码有问题 [重复]
【发布时间】:2021-09-15 23:03:32
【问题描述】:

所以,我有这段代码,我试图将我保存在 Y 变量中的文本与 x 变量中的文本进行比较。问题是 eclipse 不会将来自该定位器的文本保存在变量 x 中。如果我尝试打印变量 x,我会打印出“SECTOR 3, BUCURESTI”,这与保存在 y 中的文本相同。但是当我比较它们时,我总是会收到错误消息。

String y = "SECTOR 3, BUCURESTI";
        
        WebElement LA = driver.findElement(By.xpath("//a[@href='#']//div//div//div[contains(text(),'SECTOR 3, BUCURESTI')]"));
        String x= LA.getText();
        if (x == y) {
            System.out.println(x);
        } else {
            System.out.println("error");
        }

【问题讨论】:

    标签: java eclipse selenium


    【解决方案1】:

    请参阅此链接以了解有关字符串比较的更多信息

    Reference link

    基本上,

    您应该使用String.equals() 而不是'==' 运算符,我认为这就是引发错误的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 2021-12-16
      • 1970-01-01
      相关资源
      最近更新 更多