I have an input field that accepts numbers. I need to enter numbers and check if the error message is displayed or not. The error message shows up when an invalid number is entered. I also need to check if the error message shows up when I enter a valid number but I get NoSuchElementException
exception. The below HTML code is when an error message not displayed.
<div class="date text_feild_last">
<input type="text" id="seqNo" class="form-control" name="seq_num" value="1" placeholder="Enter Number" autocomplete="off" data-orig="921">
<div hidden id="seq-num-error" class="help-inline"></div>
</div>
The HTML code when an error message displayed is as below
<div class="date text_feild_last">
<input type="text" id="seqNo" class="form-control" name="seq_num" value="1" placeholder="Enter Number" autocomplete="off" data-orig="921">
<div hidden id="seq-num-error" class="help-inline" style="display: block;">Please enter valid number</div>
</div>
The xpath I am using to find the error message is WebElemet errorMessage = driver.findElement(By.xpath("//div[contains(text(), 'Please enter valid number')]"));
I am checking if the element is displayed and then doing my next operation but not able to carry out the next operation as I am getting an exception. Please help me. Thank you.