Я пытался написать тесты для проверки обязательных полей.Одним из полей является «Идентификатор документа».Я нашел его XPath и проверил Firefox и Chrome, и это сработало.Когда я использовал то же самое в сценарии, я получаю NoSuchElementException.Код элемента находится в:
<div class="col-xs-12 col-sm-6 edit-view-row-item">
<div class="col-xs-12 col-sm-4 label" data-label="LBL_RESUME_ID">
Document ID:
<span class="required">*</span>
</div>
<div class="col-xs-12 col-sm-8 edit-view-field " field="resume_id"
type="varchar">
<input id="resume_id" type="text" title="" value="" maxlength="255" size="30"
name="resume_id" tabindex="0" style="background-color: rgb(255, 255, 255);">
<label>
<input id="document_type_c" type="radio" title="" checked="checked"
value="Passport" name="document_type_c" tabindex="0">
Passport
</label>
<label>
<input id="document_type_c" type="radio" title="" value="DriversLicense"
name="document_type_c" tabindex="0">
Driver's License
</label>
<label>
<input id="document_type_c" type="radio" title="" value="EAD"
name="document_type_c" tabindex="0">
EAD Copy
</label>
<label>
<input id="document_type_c" type="radio" title="" value="State_ID"
name="document_type_c" tabindex="0">
State ID
</label>
<label>
<input id="document_type_c" type="radio" title="" value="Others"
name="document_type_c" tabindex="0">
Others
</label>
<div class="required validation-message">Missing required field: Document
ID</div>
</div>
</div>
XPaths, которые я пробовал:
//input[@id='resume_id']/../div
//input[@value='Others']/../following-sibling::div
Код, который я пробовал:
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement dIdErrorMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@id='resume_id']/../div")));
WebElement dIdErrorMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@value='Others']/../following-sibling::div")));
String validityMessage = dIdErrorMessage.getText();
Assert.assertEquals("Missing required field: Document ID", validityMessage);