Error message: Unable to find child element in Selenium WebDriver

I'm currently dealing with a registration page where I encountered an issue.

During my testing phase, I attempted to register without inputting a first name. Upon clicking the register button, I expected to see a 'Required' notification label.

The structure of the page can be viewed in the screenshot provided. I tried different methods such as xpath and id to locate the text from the element with id 'firstName', but it seems like all attempts were unsuccessful.

Here is my latest approach:

String test = driver.findElement(By.id("'firstName'/descendant::td[@class='alert alert-danger']")).getText();`

Can anyone help point out what I might be overlooking?

https://i.stack.imgur.com/7xViI.png

Answer №1

Attempt using the code

By.cssSelector("#firstName + registration-control-messages > div.alert")

The By selector you have chosen is incorrect.

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 present the new segment?

Having trouble with creating new sections or content after the homepage? The issue is that the new content doesn't appear on a new page but rather on the homepage itself. An example of this problem can be seen on this CodePen project, where an h1 sect ...

Alignment of close button in modal for IE7 using Bootstrap

While using Bootstrap 2 modal, I encountered an issue with the close button not being placed correctly in IE7. Given the popularity of this CSS library, I am curious if anyone has found a solution to align it properly in IE7. It seems to be related to floa ...

Animating the mobile menu transition using Bootstrap CSS

Can anyone help me with animating the mobile menu when I click the menu icon? This is what I have for the menu: .overlay-menu { position: fixed; display: none; z-index : 1040; width: 100vw; height: 100vh; background: rgba(0, 0,0, 0 ...

Printing style in CSS

Everything looks good on my webpage. For printing, my CSS adjusts the layout and section sizes. Unfortunately, there is an issue with the print layout - there is a one-inch margin on the left side causing two elements to go off the page on the right. I ...

Canceling out the overlay opacity of divs

Is there a way to ensure that when overlaying two divs with semi-transparent backgrounds, the opacity of each div does not add to one another? In simple terms, I want to maintain consistent color between the two divs even when they overlap. I have created ...

Tips for customizing the color scheme of background, rows, row selection, and headers in Angular 4 using Bootstrap 4 data tables

I've integrated Bootstrap 4 data table in my Angular 4 project, but I'm struggling to customize row colors, row selection colors, and header colors. You can check out the example of the data table I'm using at this link: https://github.com/ ...

Difficulty in breaking text within flexbox styling

I'm facing an issue where the text inside a flex container does not break correctly when the horizontal space is too small to display it all. But shouldn't it still not break even in the "normal" state? What mistake have I made here? (functio ...

Design a personalized button with a hand-shaped image using CSS

I am aiming to design a unique custom button that resembles the shape of a hand featured in this image, with the intention of adding some functionality to it later. My attempts so far have involved using an SVG path created in GIMP within a button, but all ...

"Extracting items from a list and using them to locate elements with find_element

driver.find_element_by_xpath('//*[starts-with(@href, "javascript") and contains(@href, '"(list1)[3]"')]') I'm struggling with a piece of code similar to this. It's almost functional, but the issue arises w ...

Ways to extract the hyperlink value from the href attribute

Inside my div element, there is an anchor tag containing a URL link. How can I extract the value of the href attribute? For instance, how do I retrieve the URL "https://www.tweeter.com/rkShukl" from the <a> tag? <a href="https://www.tweeter.com/ ...

What causes the discrepancy in CSS display between production and development environments in Material-UI?

Using material UI (verison: ^4.12.3) Select, with a customized input has led to an unexpected issue in the production environment. The Select input in prod has a black background and a :before element with a white background that I didn't intend to ha ...

Utilizing CSS to create dynamic 3D cube transformations

Exploring the realm of CSS 3D transforms to showcase cubes and cuboids featuring cross-sections has been my current venture. In this endeavor, I'm aiming at compatibility with Chrome, Firefox, and MSIE 11. It has come to my attention that in order to ...

Why is it that Lotus Notes is unable to render this HTML code properly?

I am having trouble with an email that displays properly on every platform except Lotus Notes. Can anyone provide insight as to why this email is not rendering correctly in Notes? Here is a screenshot: img (please note the images are for demonstration pu ...

Tips for customizing image-cropping functionality within a modal with material UI

When it comes to positioning elements on a basic page using CSS, I consider myself decently skilled. However, things get confusing when working inside a modal. I attempted to use the Dialog component from mui-material to wrap the cropper, but that approac ...

Encounters an error when attempting to use the TimerTask method in conjunction with WebDriver

With my code, I aimed to make it so that if the test exceeds 10 seconds, Selenium displays the window title and then closes it. Here is the code snippet: import java.io.File; import java.util.Timer; import org.junit.Assert; import org.junit.Test; import ...

What is the best way to ensure that child elements within a container div are centered when scrolling left and right?

When attempting to handle the 'scroll' event, I noticed that the callback function only records the position of the div as the last position. I am looking for a way to determine if the div is in the center, which is my target. const slide = ...

Is there a way to repurpose a function to work with both ids and classes?

My current code is affecting all elements instead of just the intended one. I've experimented with classes and ids, ruling out those as potential issues. I'm hoping for my JavaScript to target only the selected element, not all of them. Check ou ...

"Redirecting visitors based on their location using GeoIP targeting for

Is there a way to implement a code that redirects users based on their location? For example, if a user accesses the site from the United Kingdom, they should be redirected to /UK/, if from the US to /US/, and if from anywhere in the EU (excluding the UK) ...

How can the @FindBy annotation be used to locate a checkbox in Selenium WebDriver?

I am looking for a checkbox element <input type="checkbox" ... /> How can I use the @FindBy annotation to locate it? Is there a way to find it using value=checkbox? ...

The Click() function fails to execute

Procedure To initiate the process, first click on the Browse button within the Firefox browser. Upon doing so, a window dialogue will open prompting you to browse for a specific file. Select the desired file, which should be an AutoIt script in this case ...