static By yearFoundErrorMessage = By.className("error");
public static WebElement ca1_YearFoundError(WebDriver driver){
element = driver.findElement(By.id("yearFoundErrorMessage"));
return element;
}
//Main class from where I'm calling above function
String errorMessage = Ca1GeneralInformation.ca1_YearFoundError(driver).getText();
System.out.println(errorMessage);
<div class="controls">
<input id="ca1_GEN_foundedDate" class="error" type="text" value="2008" maxlength="4" name="data[CaInformation][ca1_GEN_foundedDate]" tabindex="5" unsaved="true">
<span id="ca1_GEN_foundedDate_error" class="inline-error ajax-failed-msg">
<span class="error" for="ca1_GEN_foundedDate">Please enter a valid year (i.e. 2013)</span>
</span>
</div>
我正在從事web應用程序,其中有跨度錯誤消息我想使用webdriver獲取此跨度的文本。以上是我的html和代碼,請幫助我。 在此先感謝。Selenium WebDriver Java - 我無法從範圍獲取動態文本
嘗試'driver.findElement(By.id( 「ca1_GEN_foundedDate_error」));'。 – JRodDynamite