Attempting to extract content from a DIV container

I have been experimenting with different methods to identify and capture the message "No matches found".

The CSS path I am currently using is "#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div"

WebElement txtMsg = driver.findElement(By.cssSelector("#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div > class.messageText"));


WebElement txtMsg = driver.findElement(By.cssSelector("#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div));

class="messageTable" border="0" cellpadding="0" cellspacing="0">No matches found

Any insights or suggestions?

Answer №1

If you are certain that the specified div contains text and your CSS path is accurate (if not, please provide the HTML source of the element you wish to extract text from), such as

<div>desired_text</div>
, then you can retrieve the text by using the getText() method:

WebElement txtMsg = driver.findElement(By.cssSelector("#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div > class.messageText"));

String divText = txtMsg.getText();

By the way, in your second example, it appears you forgot to properly encapsulate the selector with quotes:

WebElement txtMsg = driver.findElement(By.cssSelector("#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div));

Please adjust it to:

WebElement txtMsg = driver.findElement(By.cssSelector("#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div"));

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

Tips for Isolating a Single Element Within a Parent Container

I'm currently working on a basic to-do list feature where, upon checking the checkbox next to an item, both the text and delete button get a strikethrough style. Is there a way for me to apply the strikethrough effect only to the text element, leaving ...

The error message reads: `PositionOutOfRangeError: Position: 1, TotalItems:

List<WebElement> filter_icons = (ArrayList<WebElement>) driver.findElements(By.xpath(PropertyFile.read_obj("CONFIGURATION_MAJORMGMT_FILTER_LIST"))); filter_icons.size(); log.info("Data passed in Name Filter"); // Applying filter for Name filte ...

Eliminate table borders in a data grid using bslib and Bootstrap design

Within my shiny app, I am implementing the yeti theme using the bslib library along with a datatable that features bootstrap styling. However, I have encountered an issue where unwanted white cell borders are appearing in the datatable when compared to uti ...

the child element is not being targeted

My confusion lies in the fact that I am unable to realize how to properly use this. My goal is to specifically target the pre tag only when it appears within a description. p.description > pre{color:red} <p class="description"> <pre> ...

What are the steps to properly centralize a "brief biography"?

I've been struggling to align my short bio on my webpage. I used Bootstrap to create a column layout with a picture and text, but I can't seem to center it properly. Various attempts were made, including using float: left and float: right, as we ...

Firefox experiencing issues with overflowing HTML content

I am facing an issue with a table inside a div container where the content exceeds the container size. Interestingly, in Internet Explorer, the parent containers automatically expand to fit the table content. However, in Firefox, the div container only w ...

Mastering Bootstrap 4 flexbox for optimal content filling: A comprehensive guide

I am currently working on an angular app integrated with bootstrap 4. The challenge I am facing is related to the layout design. I have a fixed navbar at the top and a content area below it. Within the content area, I have a div that includes header and fo ...

What are the steps to design a fluid responsive grid with three boxes?

I really need help creating a responsive grid using CSS and HTML. The image below should give you an idea of what I'm trying to achieve. Thank you in advance for any assistance! Here is the image as a reference: https://i.sstatic.net/FO9q5.png ...

Place a button to the right side of every row to handle overflow-x

I'm trying to place a button next to each row in my table, but here's the catch: the table is inside a div with a fixed width and overflow-x for responsiveness. I want the button to appear next to each row outside of the container div. Currently ...

Having trouble sending input with send_keys in Python Selenium

Hello everyone, I have been encountering difficulties while attempting to input text data into the search box, as shown in the accompanying image. Despite my efforts to send the data using send_keys, I am consistently running into errors. The current focu ...

no visible text displayed within an input-label field

Currently, I have started working on a multi-step form that is designed to be very simple and clean. However, I am facing an issue where nothing is being displayed when I click on the next arrow. I am puzzled as to why it's not even displaying the te ...

Stop the div underneath from scrolling on iOS Safari

I have a div that has a height of 100%, equivalent to 70% of the viewport height, with an overflow:scroll property. Now I would like to add an overlaying div that touch devices can use to scroll the entire page instead of just the div. I attempted to cre ...

Navigation menu extending all the way to the far right of the webpage

This particular Angular 8 MVC C# application has been giving me a run for my money. I find myself caught in a cycle of fixing one issue only to have another one pop up in its place. Within the css file, I am setting *, html, body { font-size: 12px; font- ...

Guide to updating the button's color when clicked

I need to change the color of an iconic button when it is clicked. The default color is the primary color, but when the button is clicked, it should change to red. This functionality is working correctly. After clicking the button, two hidden buttons shoul ...

"Modify the CSS color of h1 based on the presence of a specific class containing spaces in a div

I am currently attempting to modify the color of a heading by referencing a specific div's class. My attempts so far include: .pagetitle-title.heading { color: purple; } <div class="container"> <h1 class="pagetitle-title heading">I ...

Implementing a hamburger menu across various webpages

I recently followed a tutorial on adding a hamburger menu from this YouTube video. The menu works perfectly on the INDEX.html page, but when I try to add the same code to other pages like "contact" or "about", none of the menu features seem to work. I rea ...

How can the instance value be transferred from one class to another class that contains a test annotated method?

Class1-UIHandler1.java public WebDriver Assettype_dropdown(WebDriver driver,WebElement dropdown,String name) throws InterruptedException { wait_until_clickable(driver,dropdown,120); dropdown.click(); search.click(); search. ...

Discover the steps for launching multiple web pages simultaneously with Selenium Driver in the .Net framework!

I have been utilizing Selenium IWebDriver to launch multiple websites in Chrome. In my .Net application's user interface, there is an Add button where I enter a website address and upon clicking the button, it should open in the Chrome browser. The f ...

Attempting to change the src of a different image using jQuery upon clicking

I have two separate divs that change their background image source when clicked, which is working fine. However, I would like them to change the other image they are paired with. For example, if div 1 is clicked and becomes "open", then if div 2 is "open" ...

Flex mode allows for responsive row details in ngx-datatable

Having an issue with my ngx datatable row details. Everything works well initially, but when I adjust the browser width, the details don't scale properly with rows and columns. They seem to have a fixed width that was set when the page was first loade ...