Testing scenarios for password changing functionality using Selenium - Troubleshooting

Here is the test I've written for changing a password:

@Test

    public void changePassword() throws IOException, InterruptedException {
        Login();
        driver.findElement(By.xpath(".//*[@id='wrapper']/div[1]/div[2]/div/div/ul/li[3]/a")).click();
        driver.findElement(By.xpath(".//*[@id='wrapper']/div[1]/div[2]/div/div/ul/li[3]/ul/li[3]/a")).click();
        driver.findElement(By.xpath(".//*[@id='change-password']/div[1]/div/input")).sendKeys("abcd");
        driver.findElement(By.xpath(".//*[@id='Users_password']")).sendKeys("xyz123456");
        driver.findElement(By.xpath(".//*[@id='repassword']")).sendKeys("xyz123456");
        driver.findElement(By.xpath(".//*[@id='change-password']/div[4]/div/input")).click();
    }
}

I encountered the following error. Despite verifying the Xpath is correct, I'm still getting this error -

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='change-password']/div[1]/div/input"}
Command duration or timeout: 2.81 seconds
   ...
   (error details continued)

My questions are - 1. What could be the issue in the code provided above, as it navigates me to the change password screen. 2. Is the method used for testing the change password functionality optimal? 3. Can you suggest any additional test scenarios and how to include them?

Answer №1

Begin by incorporating an HTML snippet, allowing the locators to be expressed in a more redundant manner.

Secondly, implement a wait mechanism to ensure that the page is fully loaded. In this scenario, when clicking on a link and attempting to input data into the change password field, an exception may occur if the page has not completely loaded and Selenium tries to enter the value prematurely.

An easy fix is to utilize Implicit wait:

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

Answer №2

Here are the Responses to your Inquiry:

  1. Identifying Issues in the Code:

The xpaths provided, such as

.//*[@id='wrapper']/div[1]/div[2]/div/div/ul/li[3]/a
,
.//*[@id='wrapper']/div[1]/div[2]/div/div/ul/li[3]/ul/li[3]/a
and
.//*[@id='change-password']/div[1]/div/input
, are absolute xpaths that use index. This makes them fragile and susceptible. It is recommended to create unique logical xpath.

  1. Is Testing Change Password Functionality Optimal?
    :

Making a decision on the best method varies depending on the specific scenario. It is important to note that before using sendKeys("abcd") for a text field, ensure to utilize the clear() method beforehand.

  1. In cases of
    NoSuchElementException: Unable to locate element
    , it is advisable to implement ExplicitWait with appropriate ExpectedConditions so that Selenium can locate the element successfully.

Feel free to reach out if these Responses address your Query.

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

What is the best way to extract the artist's name from this JSON data structure?

Here is a lengthy JSON object that I am working with. I need to extract the name of the artists from it, specifically under tracks -> items -> album -> artists -> name. Despite my efforts, I am unable to retrieve the artist name using the code below. Take ...

The error message "net::ERR_NAME_NOT_RESOLVED" appeared while using Selenium in Python to scroll down a webpage

Currently, I am in the process of developing a Python scraper using Selenium to gather website information. However, I encountered an issue when trying to access a page that is not live, resulting in the error: unknown error: net::ERR_NAME_NOT_RESOLVED It ...

Combining AngularJS with Servlets: A Seamless Integration

I am attempting to retrieve a JSON object from a servlet by calling a function through a link in my HTML code. Below is the HTML link that calls the fTest function: <td><a href="" ng-controller="minaplantaCtrl" ng-click="fTest(x.id_camion_descar ...

I'm attempting to retrieve text from an <a> tag with a ::before selector using selenium in python

<ul class="ipc-inline-list ipc-inline-list--show-dividers ipc-inline-list--inline ipc-metadata-list-item__list-content baseAlt" role="presentation"> <li role="presentation" class="ipc-inline-list__item"><a class="ipc-metadata ...

Having trouble with selecting a value by right clicking in Selenium Webdriver?

Is there a way to simulate a right click using Selenium WebDriver in order to open a context menu? I need to select "Show CTR Impressions Label" from the menu that appears when I right click on a date highlighted in red. I have been successful in right cl ...

Error: OpenQA.Selenium.ElementNotVisibleException: 'Element cannot be found'

Having trouble with finding and clicking on an element using the page's xpath. Even after inspecting it in firebug, the path does not work. Firebug can identify both the relative path and absolute path, but still the element cannot be found? IWebDriv ...

Are two distinct elements sharing the same xpath?

While attempting to test the functionality of a website using JUnit and Selenium, I encountered an issue with selecting currencies from the "Currency I Have" and "Currency I Want" dropdowns. The xpaths for both options turned out to be the same, causing su ...

Is it possible to reuse a WebDriverWait instance?

When working with a page object that interacts with various elements on the DOM, is it better to create a single instance of WebDriverWait on initialization and use it for all waits? Or should separate instances be created for each element being waited on? ...

Trouble arises with the Selenium feature when attempting to choose a particular article within a Tree component by utilizing a dynamic XPath

Currently, I am working on developing a Selenium function that has the ability to select a specific article within a Tree component. This particular article has been previously identified using the search bar and is the only available element at that time. ...

Methods for turning off Flash in the remote webdriver using selenium

Is there a way to prevent the loading of flash objects while using Selenium Remote WebDriver? I would also appreciate a solution for the normal WebDriver. In many cases, Flash objects are loaded by JavaScript. I have attempted to disable JavaScript on bot ...

How can I prevent scrolling while a loader is displayed during page loading?

How can I disable scrollability on my personal website when the page is loading with the loader wrapper? I have tried using overflow: hidden; in the CSS but it didn't work. The loader is set to display for 2.5 seconds. Any suggestions on how to achiev ...

The host named selenium could not be resolved

I am trying to test my Laravel project using Dusk. However, when I run the command php artisan dusk, I encounter the following error: Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with para ...

TestNG encountered an exception: Unable to create an instance of the class

Encountering the 'Cannot instantiate class' error while running a test case in Selenium WebDriver using Java (using Maven project). Here is the parent class where the driver and properties are defined: package com.example.base; import java.io ...

Looking for a solution for Selenium to troubleshoot issues with clicking on radio buttons

I'm facing an issue with clicking on a radio button using Java Selenium and JUnit. Although the syntax seems correct and the button is located, I'm still encountering an exception which states: org.openqa.selenium.ElementClickInterceptedExceptio ...

Automate the process of logging into websites by utilizing selenium webdriver technology

Having trouble logging in to a website using selenium webdriver and excel VBA, specifically getting stuck at the log in page Below is the code being used: Dim bot As New WebDriver bot.Start "chrome", "myurl" bot.Get "/" 'select from drop down bot. ...

Error: Session creation failure - Selenium Webdriver requires Chrome version to be x.y.z or higher to function properly

One challenge I face is that I am utilizing c9.io for cloud development, which requires the gem webdrivers to run Chrome with Watir, instead of setting an executable path to Chrome on my local device. My code was functioning properly until I encountered th ...

Exploring Ways to Retrieve Mouse Hover Messages in Selenium WebDriver Without Access to HTML Source Code

I am interested in extracting the message text that displays when hovering over a text or info icon. ...

How can I show a webdriver instance on an embedded iframe website?

Currently facing an issue with opening the webdriver instance on my HTML page using Java. WebDriver driver = new ChromeDriver(); // Trigger the Application The following code is used to initialize the Chrome driver instance. ...

Are there alternative, more dependable methods for executing a click command on an element in Headless Chrome using Selenium?

For the past two days, I have been struggling with a frustrating issue involving the click() command in Headless Chrome. Specifically, I have been trying to click on an Anchor (a) element with a href tag, and despite trying various suggestions found in dif ...

Can the System Property be permanently configured in InteliJ?

I encountered some challenges with running Selenium tests. After much troubleshooting, I discovered a solution that involved adding an additional dependency and including a line of code to be executed before running the tests as outlined in this Stack Over ...