Uncover the HTML tag associated with specific text on a webpage with the help of selenium

<div class="searchSummary floatL">
<span>18</span>
results for "gloves"
</div>

Can someone assist me in using Selenium to extract the 'span' tag containing '18'? I am trying to specifically retrieve the 'span' element.

I would appreciate any guidance on achieving this task with Selenium and CSS. Thank you.

Answer №1

If you're working with Selenium using Java and you have a WebDriver named driver, you can try the following code snippet:

driver.findElement(By.cssSelector("div.searchSummary.floatL span")).getTagName();

To make it more versatile (such as finding the tag name of a span with specific content), you can use XPath like this:

driver.findElement(By.xpath("//div[@class='searchSummary floatL']/*[contains(.,'18')]")).getTagName();

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

supplying various color variables to a single class

I am working on a webpage with multiple elements sharing the same CSS class. I want each element to have a unique background color, but I don't want to create a bloated CSS file. Is there a way to achieve this by adding a parameter in my HTML like cla ...

Alter the background of cards in real-time

I am unfamiliar with JavaScript, but I wish to utilize a function to alter the background color of multiple cards. function ChangeColorToGreen() { document.getElementById("ChangingCard").style.background = "green"; } function ChangeColorToPurple() { ...

Tips for choosing an element using a reference element in Selenium WebDriver

As someone who is new to selenium automation, I have encountered a scenario where I need to click on a button based on a specific title. However, the button element appears the same for all rows in the table. This is what it looks like: https://i.sstatic.n ...

When viewing a webpage on a small browser, the content will automatically expand to fill the

Attempting to utilize responsive CSS media queries to hide the sidebar unless the screen is large or a tablet big enough in landscape mode. It appears to be functioning properly while resizing the browser, but at a certain size, it occupies the entire scre ...

Issue with loading background image in HTML/CSS is being caused by a Cross-Origin Read Blocking problem

As part of my project, I need to load an image from my image hosting site by using my github repository. The CSS code I am using for this task is as follows: #main-section{ background-image : url("https://github.com/<mypath>/myphoto.jpg"); } Be ...

How can I programmatically click the send button on WhatsApp using Selenium, either through xpath or css selectors in vb.net

Looking for help on using Whatsapp XPath or CSS with Chromedriver in VB.NET. HTML: <span data-testid="send" data-icon="send" class>...</span> ==$0 XPath: //*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2 ...

Apply this class exclusively for mobile devices

Is there a way to add the class p-5 only for mobile devices? For desktop computers: <nav class="navbar navbar-expand-lg navbar-light bg-light" style="padding:0px 10px 0px 10px;"> For mobile devices: <nav class="navbar navbar-expand-lg navbar-l ...

GeckoDriver is encountering some difficulties, whereas Chrome Driver is functioning properly

In order to download files for a current project, I've taken on the task of creating a script. The challenge arises as my company has blocked the site on Chrome, but not on FireFox, prompting me to attempt using Geckodriver. However, I keep encounteri ...

Adjust the display from none to block when the parent element is set to flex

JSFiddle Demo Issue with - .popupcard_first:hover .popupcard_first { display: block; } I am trying to link the :hover effect to the first card only, but the only way I could make it work is by changing .popupcard... to .featured_cards:hover .po ...

Fixed position does not adjust based on the screen resolution

If I were to create a web page, I would include a main menu that always remains on the screen, similar to this design: There are no issues with screen resolution exceeding 1300px, as seen in the image above. However, when attempting to resize the browser ...

Visual Studio 2017 experiencing compatibility issues with Bootstrap

I've been working on creating a carousel using bootstrap within Visual Studio 2017. I utilized the NuGet package manager to install jQuery and Bootstrap, and to test its functionality, I generated a bootstrap snippet for the carousel. Take a look at ...

Validation of request using Selenium

I am currently working on creating automated tests using Selenium with C#. One of the key functionalities I want to test is whether a certain action on the page triggers a request to a specific host. While I know how to manually check this using tools lik ...

Press a sequence of buttons repeatedly

I am looking to automate my Angular application using Selenium Web Driver. I have implemented a code snippet to handle a series of dialog windows with OK buttons: // Check if Survey exit window is displayed and click OK button clickConfirmWindow(driver, SU ...

Modify top position without affecting bottom alignment using CSS

I am currently working on a website that is designed to mimic a printable document. The layout consists of a header, body, and footer, with each element utilizing CSS for margin and height adjustments. The challenge lies in ensuring that the footer is alw ...

Is it possible to categorize elements for focus and onblur events?

In my search feature, I have implemented an autocomplete div that appears when the user types in a search field. The issue I am facing is that I want the div to disappear when the user clicks outside of it. Here is what I have attempted: //SHOW THE DIV WH ...

Is there a way to show textboxes stacked on top of each other without causing them to

Here is the HTML snippet I am working with: <div> <p><label>Faculty <input type="text" class = "f"></label></p> <p><label >Department<input type="text" class = "f"></label></p> ...

Saving an alert message triggered by an action in Selenium using JAVA

I am currently working on running a test in TESNG to check for the presence of a specific popup message displayed on the screen. My experience with Selenium and Java is still at a beginner level. After performing an action by clicking a button, I expect ...

What is the best way to ensure my checkboxes are positioned on individual lines?

I am trying to vertically align my checkboxes so that each option appears on a separate line. I searched online and found suggestions to use vertical-align: middle, but that only changes the position of the label. I want each checkbox to be displayed on it ...

When I access the website through the LinkedIn app, my CSS styles are getting jumbled up

Is there a way to resolve the problem I'm facing with CSS when accessing the site through the LinkedIn app on iPhone? The issues don't occur on Android. If anyone has a solution, please share. Thank you :) Click Here ...

DIV collapsing in reverse order from the bottom to the top

Looking for some help on how to create two links that, when clicked, will scroll a hidden <div> up to fill the full height of its parent container. I've been having trouble with the element using the full height of the <BODY> instead. ...