简体   繁体   中英

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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