简体   繁体   English

Selenium WebDriver 测试跨度

[英]Selenium WebDriver test for span

I'm actually trying to design a test case for element in the span我实际上正在尝试为跨度中的元素设计一个测试用例

    <div class="one">
    Annual Salary
    <span>€40,000</span>
    </div>

My code is:我的代码是:

String expected = "€40,000";
WebElement resultTextBox = MyDriver.findElement(By.cssSelector("#results1 > div.wrapper > div.one > span"));

String TestResult = resultTextBox.getText();

if (expected.equalsIgnoreCase(TestResult)) {
    System.out.println("Test Case Pass");
}
else
{
    System.out.println("Test Case failed");
    MyDriver.close();//close
}

Use the following code for WebElement that contains span text as xpath:对包含跨度文本为 xpath 的 WebElement 使用以下代码:

WebElement resultTextBox = MyDriver.findElement(By.xpath("//span[text()='€40,000']"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM