Issue with Selenium WebDriver: Expectation failure while waiting for element visibility at specified location(..)

I'm facing a little issue with my automated test. Whenever the test encounters an error like this:

Expected condition failed: waiting for visibility of element located by(...)

I find it difficult to pinpoint the exact problem.

@BeforeMethod
public void BeforeTest(){
    System.setProperty("webdriver.chrome.driver", "C:/drivers/chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.navigate().to("https://poczta.o2.pl/rejestracja/");
}

@Test
public void Test(){
    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[name='9cb78dee-04b3-01d5-524b-9159a1646cd3']")));

    WebElement user = driver.findElement(By.cssSelector("[name='9cb78dee-04b3-01d5-524b-9159a1646cd3']"));
    user.sendKeys("Cezary");

    WebElement user2 = driver.findElement(By.cssSelector("input[name*='42aced']"));
    user2.sendKeys("Znojek");

    WebElement male = driver.findElement(By.id("male"));
    ((WebElement) male).click();
}

Can you help me identify the root cause of the issue?

Answer №1

It seems that the name

9cb78dee-04b3-01d5-524b-9159a1646cd3
is constantly changing. For instance, when I recently visited the page, the "first name" section appeared like this:

<input type="text" name="2a810eef-304a-e7bb-d148-f9655e639f02" aria-labelledby="0bd5980e-a03a-4dd9-1302-105b999c3afc" class="invalid sc-bZQynM bZqAGh" autocomplete="off" value="">

Hence, it's unreliable for identifying the object. In the case of that specific form, I suggest focusing on the label and then locating the associated input field. Both are contained within the same div, making them easily distinguishable:

<div class="">
    <label id="790a1161-7317-afc5-7563-1973254ccc96" class="sc-dnqmqq dsXufX">Imię</label>
    <input type="text" name="885f994f-f81e-7142-c3f0-61420449b0b7" aria-labelledby="790a1161-7317-afc5-7563-1973254ccc96" class="sc-bZQynM bZqAGh" autocomplete="off" value="">
</div>

In XPath, you could represent it as follows:

//label[text()='Imię']/../input

(select the label, go back to the parent, and then choose the input field under the same parent)

This method of selection is also more semantically clear, as it explicitly specifies what you are selecting (the name field), unlike using GUIDs which lack descriptive information.

Unfortunately, achieving this in a CSS selector might not be feasible since it doesn't support text-based selection (although I could be mistaken, as CSS selectors aren't my area of expertise).

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

Python Selenium package encountering formatting issues

Currently on Linux Debian 9 and using PyCharm for web scraping with Python 3.5 as interpreter. This is the script being used: from selenium import webdriver import time import datetime from selenium.webdriver.common.keys import Keys Everything works fin ...

Steps to download a file using Selenium and Java

Could someone help me figure out how to download a file (specifically an mp3 file) using selenium webdriver with Chrome browser? When I attempt to access the URL for the mp3, it just starts playing instead of downloading. Is there a way to force it to do ...

Selenium Webdriver for Repeatedly Browsing Pages

I'm currently struggling with creating a loop for the explanation provided in the link below. Can you help me figure it out? https://drive.google.com/file/d/0B9-9eJW3sN3tS0hnMU9pd29SX2s/view?usp=sharing ...

Previewing the small version, loading the URL into a container

Currently, I am working with jQuery's .load(url, ...) function to bring in a url and display it within a div. However, I am facing an issue where the result needs to be resized in order to fit correctly within the layout. Can anyone provide guidance o ...

Tips for creating a fading effect when hovering over a div element

Hello, I am currently working on a project where I have a span that displays over an image on hover. I would like to add a bit of javascript or css transitions to make this div fade in to about 0.8 opacity when hovered over, and then fade back to 0 opacity ...

Animate the appearance of list items sequentially using CSS animations

Is there a simpler way to achieve the effect of having list items slide in one after the other? The CSS method provided here seems quite intricate. #nav ul.is-visible{visibility:visible;opacity:1;-webkit-transform:scale(1);-ms-transform:scale(1);transfo ...

Why might an element become unclickable even though it appears to be the same element?

At times, an issue arises where clicking on an img WebElement fails, with the error message claiming that the Element is not clickable even though the element receiving the click is the same. For instance, in a dialog with a close button containing an img ...

What is the best way to display a responsive website design exclusively for certain devices?

My website currently lacks responsiveness. Typically, we can check if a website is responsive by resizing the browser to see if it adjusts using CSS3 media queries. However, I am looking to create a better user experience by ensuring that visitors using a ...

Styling with CSS to create a layout similar to Facebook Messages

I am attempting to design a web layout similar to Facebook's Messages page, with a fixed height header and footer, and a flexible height main element. Within the main element, there needs to be: A div (100% height of the main elem.) that is scrolla ...

In a remarkable design with an array of buttons and an individual div assigned to each, a fascinating functionality unfolds. Whenever a

https://i.stack.imgur.com/emhsT.png When I click on the first "Respond" button, I want the adjacent text box to disappear. Currently, if I click on the first "Respond" button, both text boxes will disappear instead of just the first one. $('.comment ...

Using cascading style sheets to switch a page into editing mode

Is it possible to change the view of a page after clicking a button without using javascript, and instead relying solely on CSS? I want to display a page with information where users can click an edit button and make changes within the same view rather th ...

Icon with label and border using Font Awesome

I'm looking to recreate this design using HTML and CSS: https://i.sstatic.net/LUgGW.png The icon I'm trying to replicate is actually from font awesome. Here's what I've accomplished so far: https://jsfiddle.net/0Lewug6p/1/ &l ...

troubleshoot clientWidth not updating when CSS changes are made

Summary: When I adjust the size of a DOM element using CSS, its directive fails to acknowledge this change even with a watch on the size. Aim I have multiple custom directives (simple-graph) each containing an svg. My goal is to enlarge the one under the ...

What is the best way to display grouped items horizontally in an ASP.NET ListView?

My ASP ListView currently displays items vertically in columns with GroupItemCount set to 3: A D G B E H C F I Is there a way to adjust the display so that it groups items horizontally in rows like this? A B C D E F G H I This is the ListVi ...

Tips on utilizing browser scroll for horizontal overflow of internal div?

I'm working on creating a dynamic page with a tree-like structure that easily exceeds the width of the browser window. My goal is to enable horizontal scrolling for the entire page using the browser's scrollbar, without needing a separate scrollb ...

Obtain the following image with every click

I have a div with images inside. I created two arrows (previous, next) within a larger div using the src of one of the images as the background URL for each arrow. My goal is to make the next arrow change the large image to the src of the following image w ...

Passing on Emails using Java

I need my Java-based software to forward messages sent to a specific address to a particular group of recipients. For instance: Messages sent to <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7512071a00054435180c061c01105b1 ...

Is it possible to turn a <span> element into a clickable hyperlink?

Can a span be turned into a clickable link? I have successfully made a span with only a background image (using the Gilder/Levin image replacement technique) into a clickable link. This seems to work well on my desktop in Chrome, Opera, and IE 11. Is thi ...

Creating a personalized navbar design using Bootstrap

I'm attempting to build a navbar using bootstrap 4: However, I am uncertain of how to achieve this :/, can anyone offer any advice?! I am specifically interested in the lines on the left and right of the navbar, as well as the image centered in the m ...

I struggle with creating an xpath for dynamic elements

I'm encountering an issue in the following situation. Can you please assist me with this? Scenario- Visit URL- Click on <MF> folder. Click on <COMMON>. Click on <DEC-2017> folder. Click on <Current date> folder <Current ...