Unable to find an error message within Selenium for validation

I was attempting to create tests to verify mandatory fields. One of these obligatory fields is labeled as "Document ID". I managed to locate its XPath and verified it in both Firefox and Chrome, where it worked fine. However, when implementing the same XPath in my script, it resulted in a NoSuchElementException being thrown. Below is the code snippet for the element:

<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>

Below are the XPaths that I experimented with:

//input[@id='resume_id']/../div
//input[@value='Others']/../following-sibling::div

The WebDriver code snippet used:

WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement dIdErrorMessage1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@id='resume_id']/../div")));

WebElement dIdErrorMessage2 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@value='Others']/../following-sibling::div")));

String message1 = dIdErrorMessage1.getText();
String message2 = dIdErrorMessage2.getText();        
Assert.assertEquals("Missing required field: Document ID",message1);
Assert.assertEquals("Missing required field: Document ID",message2);

Answer №1

One method to try is to directly verify the text within the element:

//div[text()[normalize-space()='Document ID:']]

If this approach does not work, please indicate the specific element or text you would like to confirm.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript contains an element that can be utilized for hovering over with Selenium

When using Selenium-Java to navigate the Amazon.com website (url: www.amazon.com), my goal is to first hover over "Departments", then select "Books & Audible" and ultimately land on the "Books" page within the "Books at Amazon" section. The problem I am e ...

What is the best way to update the ChromeDriver or EdgeDriver automatically using VBA?

In my quest to find a solution for automatically updating Selenium EdgeDriver, I have scoured the internet. Anyone who uses SeleniumBasic understands the inconvenience of having to manually download the driver from the website whenever their main browser u ...

Using AJAX to send a request with an image to a Spring MVC controller

I am attempting to utilize AJAX to send an image: function uploadImage() { var image = document.getElementById('image').files[0]; var formData = new FormData(); formData.append('image', image); $.ajax({ url: &ap ...

Ignoring empty lists in Jackson - A simple guide

My web service needs to pass these entities as JSON objects: @Entity(name = "exams") public class Exam { @Id @GeneratedValue private int id; @Column(name = "exam_name") private String name; @JoinColumn(name = "exam_id") @One ...

Selenium Chromedriver fails to redirect to specified website

Currently, my code looks like this: chrome_options = Options() chrome_options.add_extension(r"C:\Users\x\OneDrive\Desktop\pp\crxSolver.crx") driver = webdriver.Chrome(r'C:\Users\x\OneDrive\Desktop&bso ...

Error: The session ID is not currently active

I encountered a problem with my tests failing when running them on TFS, showing the following error: WebDriverError: No active session with ID Failed: No active session with ID Interestingly, these same tests are passing locally. Everything was working ...

Limiting capture group options in Cucumber for dynamic parameters: A comprehensive guide

Currently, I am working on creating a test automation step-definition using Cucumber and WebdriverJS. The scenario involves validating certain actions based on different service methods. Scenario Outline : Validate functionality for different service metho ...

What could be causing an undefined error when running Javascript with Python and Selenium?

My goal is to utilize Javascript for retrieving a table body element on a webpage. Upon executing the script immediately, I receive an undefined response. However, if I introduce a few seconds delay, it functions correctly. def fetch_row_list(browser): ...

Decoding a JWT Base64 string into JSON format

While attempting to convert a base64 encoded JWT header into a string, I encountered an unexpected output: {"alg":"RS256","typ":"JWT","kid":"1234" The output seems to be missing the closing bracket. However, when I decode the same base64 string usi ...

Is it possible to use Webdriver (ChromeDriver) alongside Play framework?

Currently, I am facing an issue with ChromeDriver within the Play! framework. In my UnitTest, I have instantiated ChromeDriver to make a get request to my Dyndns URL. However, upon initiating the test, Chrome opens, makes the request, but unfortunately, th ...

Error 111 encountered in Python when using HtmlUnit and Selenium in combination

Attempting to integrate selenium with HtmlUnit into my Django application. This is the process I'm following: To start in the background, I use: java -jar selenium-server-standalone-2.27.0.jar bg Here is the code snippet: from selenium.webdriver.co ...

Tips for utilizing JSON for mapping files

Hey there! I am currently developing a 2D game using libgdx and I'm in need of a method to save vertices from an editor I've been working on. My initial thought was to store everything in JSON format. { meshes: { attributes: {"POSITION", "CO ...

What is the proper way to identify this element in Selenium?

After crafting this piece of code driver.findElement(By.xpath("//input[@type='textarea']")).sendKeys("foo"); This was the outcome BrowserController.remoteControl(): Unable to locate element: //input[@type='textarea'] https://i.stack ...

Utilizing PostgreSQL's JSON column to store and retrieve data in a Hibernate entity

I am currently facing a challenge with mapping a JSON column in my PostgreSQL DB (version 9.2) to a JPA2 Entity field type. Initially, I attempted to use String as the value type, but encountered an exception when attempting to save the entity due to a co ...

An error occurred in the devtools session due to a WebException, stating that the remote name could not be resolved for 'http'

After setting up a new session to Support DevTools Session on docker for selenium 4, I encountered an issue. Everything seems to be working as expected during debugging until I reach the devtools session, where I encounter the error "WebException: The re ...

Error message: IndexError: list index out of range while attempting to trigger a click event using selenium

There are a total of 41 category checkboxes on the page, with only 12 initially visible while the rest are hidden. To reveal the hidden checkboxes, one must click on "show more." This simple code accomplishes that: [step 1] Loop through all checkboxes >> ...

Executing Mustache templates with JSON or Strings in Android can be achieved by following these steps

I possess a String object with a template foundation, similar to this: <h1>{{header}}</h1> {{#bug}} {{/bug}} {{#items}} {{#first}} <li><strong>{{name}}</strong></li> {{/first}} {{#link}} <li><a h ...

Tips for identifying the existence of an element using Selenium WebDriver in Java

When attempting to use Selenium WebDriver's findElement() function to check for the presence of an element on a page, I encounter issues where Selenium exits the code even when handling exceptions with WebDriverException. Although I tried implementin ...

What is the best way to conduct testing on our Chrome extension using the Selenium tool?

I have developed a Chrome extension and am working on creating an automatic Selenium test to ensure its functionality. Below is the Java code I have written for this purpose: public static void main(String[] args) throws InterruptedException { WebDr ...

Discovering the process of choosing a city name during web scraping in Python for Justdial

As a newcomer to web scraping, I am attempting to extract information from the Just Dial website. My goal is to allow users to enter any city name of their choice directly into the program. When using the code snippet below: driver.find_element(By.XPATH,&q ...