The anticipated scenario did not meet expectations as the element being waited for to become clickable, specified by the XPath //*[@id="documentation"]/div/div[2]/div/button, failed the

I have been attempting to click on a specific button using SELENIUM & JAVA but I keep encountering this error message:

Expected condition failed: waiting for element to be clickable: By.xpath: //*[@id="documentation"]/div/div[2]/div/button (tried for 10 second(s) with 500 milliseconds interval)

The button in question looks like this:

<button type="button" class="btn btn-sm btn-link add-row">Upload FILE</button>

Here is the XPATH for the button:

//*[@id="documentation"]/div/div[2]/div/div/button

These are the steps I followed:

WebDriverWait wait10735 = new WebDriverWait(driver,Duration.ofSeconds(10));
        JavascriptExecutor executor3735  = (JavascriptExecutor)driver;
        WebElement elementCat4735=wait10735.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"documentation\"]/div/div[2]/div/button")));

Where am I making a mistake?

Answer №1

By simply using the xpath below:

//button[text()='Upload FILE']

You should find success.

What caused this issue?

The problem lies in your previous use of the xpath:

xpath //*[@id=\"documentation\"]/div/div[2]/div/button

This xpath is navigating through multiple parent elements before reaching the button, making it fragile to changes in the structure of the page. It's best practice to base your xpath on the properties of the element itself rather than its surroundings.

In this case, I utilized the text of the element for a more stable xpath expression.

If feasible, consider collaborating with developers to assign IDs to elements crucial for automation. This teamwork can ensure smoother operations!

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

Using copyTextureToTexture in three.js creates unsightly aliasing artifacts

Whenever I attempt to use the copyTextureToTexture function to copy texture1 (which contains a loaded image) to texture2 (a datatexture that was created with the same dimensions and format), I encounter severe aliasing artifacts. It seems like most of the ...

I'm having trouble deciding between PHPUnit_Extensions_Selenium2TestCase and PHPUnit_Extensions_SeleniumTestCase. Can anyone help me choose the right one to use for

When deciding between PHPUnit_Extensions_Selenium2TestCase and PHPUnit_Extensions_SeleniumTestCase, which one should be chosen and why? https://github.com/sebastianbergmann/phpunit-selenium/blob/master/Tests/Selenium2TestCaseTest.php All the functions ...

Angular 4: Implementing a Re-login Dialog/Modal Using Interceptors

Issue Description I recently started working with Angular 4 and I am facing a challenge in handling user re-logging when the token expires. Let's Dive Into the Code I have implemented a response intercepter that checks for a 401 error in the respon ...

Navigating different domains in ExpressJS - Handling CORS

Currently, I am facing a challenge in setting the domain for a cookie that I am sending along with the response from my ExpressJS implementation. Unfortunately, at the moment, it is only being set to the IP address of where my ExpressJS server is located. ...

The Selenium webdriver seems to be having difficulty locating the button

Here is the button link I am working with: <a class="button" href="#" onclick="ajaxtoelement('include/system.php?mode=begin&amp;location='+getSelectedValue('location')+'&amp;terminallane='+getSelectedValue('te ...

Decrease the size of the mat-flat-button

I have a message board where I am trying to incorporate delete buttons. However, when using the mat-flat-button feature, it appears to be increasing the height of the message items. If I adjust the button's height to 50%, then the button becomes half ...

Error: When trying to run npm start in a React project, an issue arises where the property 'prototype' is undefined and results in

Having trouble while running my react app, I am encountering an issue. Can someone please assist me with this? A TypeError is showing up: "Cannot read property 'prototype' of undefined". This error is displayed on the browser page. The terminal o ...

Unable to access code search functionality during the process of scraping from GitHub

Trying to create a simulation of the online GitHub search using Selenium web scraping. Struggling to make the program search within the Code section instead of repositories. Here is the code snippet: FirefoxProfile p = new FirefoxProfile(); p.setPref ...

Creating a folder for a particular purpose in C#: A step-by-step guide

I have integrated Selenium for automation purposes. I have structured my code with a screenshot class and Page Object method to organize elements in separate classes for each page. Currently, I am taking screenshots of each page by calling the get screensh ...

What's with all the super fast content popping up on my browser when I begin my intern test?

Hello everyone, First of all, I want to express my gratitude in advance. I am currently executing a single functional test utilizing intern and local selenium. During the initiation of the test, the following sequence occurs: The Chrome browser is laun ...

Ways to extract all hyperlinks from a website using puppeteer

Is there a way to utilize puppeteer and a for loop to extract all links present in the source code of a website, including javascript file links? I am looking for a solution that goes beyond extracting links within html tags. This is what I have in mind: a ...

Tips for applying various CSS properties to a single element using styled-components

Is there a way to style similar elements differently using different CSS properties in styled components? For example: <div></div> <div></div> With the knowledge I have, I can do: export const StyledDiv = styled.div` color: red; ` ...

Executing web driver and Tor in Java

Is it possible to connect to Tor using PhantomJS or HtmlUnit driver in addition to Firefox driver? For PhantomJS, I attempted the following code: String[] phantomArgs = new String[] { "--webdriver-loglevel=NONE", "--webdriver=localhost:9150" }; ...

Tips for creating a personalized callback within a user function using JavaScript

Utilizing callbacks is a common practice when working with third-party libraries like jQuery. However, I have encountered a situation where I need to implement my own callback function. Consider the following snippet from my current code: // Get All Rates ...

Exploring sections of a GLTF import within the primary rendering loop (apologies for any beginner questions)

As a Unity developer venturing into learning Three.js, I've come across a seemingly simple yet frustrating issue. My goal is to import and animate a 3D logo consisting of four separate meshes (elem1 to elem4) in my Three.js application. After exporti ...

Here is a unique rewrite of the text: "Learn the process of toggling the tabindex for

Is there a way to dynamically change the tabindex of an element based on its visibility in the viewport? I am looking to either reset the current tabindex when entering a new section and assign new values to elements within that section, or disable and re- ...

Execute chromedriver within the present directory of my Python project

I have a python project called 'SRC' and I am currently getting the chromedriver.exe from an absolute path on my PC: executable_path='C:\programs\chromedriver.exe' Is there a way to get it from the current source directory of ...

What are the functioning principles of older ajax file uploading frameworks (pre-html5)?

Traditional HTML includes an input element with a file type option. Tools are available that enable asynchronous file uploads with progress tracking. From what I gather, this is achieved by splitting the file into chunks and sending multiple requests wit ...

Access denial encountered when attempting to submit upload in IE8 using JavaScript

When running the submit function on IE8, I am receiving an "access is denied" error (it works fine on Chrome and Firefox for IE versions above 8): var iframe = this._createIframe(id); var form = this._createForm(iframe, params); ... ... ...

Steps to deactivate two choices in a multi-select dropdown menu and visually dim those options

Hey there, I recently worked with Angular8 and Bootstrap 4. I utilized a Bootstrap multi-select dropdown, where I encountered an issue: specifically, I'm trying to disable and gray out the options for PL Marketing and CL Marketing but have been unsucc ...