Extracting specific information from HTML using Selenium in Python

Trying to extract a specific piece of text from an HTML page using Selenium webdriver and the class name. Below is the snippet of the HTML code:

<tr> 
   <th>
   <td class="max-captured">174.26 kp/s</td>
   <td class="max-captured">0 p/s </td>
</tr>

The goal is to retrieve only the text "p/s". Is this achievable? Appreciate any help.

Answer №1

One way to select elements on a webpage is by using css_selector

For example, you can use the following code snippet in Selenium:
driver.find_element_by_css_selector('tr th .max_captured:nth-child(2)').text

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

Guide to eliminating any negative numbers from a list using Python's lambda functions

After successfully implementing a lambda function to sort a list, I am now looking to remove all the negative objects from the list using lambda functions. dto_list.sort(key=lambda x: x.count, reverse=True) Is there anyone who knows how to write the lamb ...

What is the best way to format a list for writing into a file?

I am working with a Python list and I want to format it in a specific way. Input: trend_end= ['skill1',10,0,13,'skill2',6,1,0,'skill3',5,8,9,'skill4',9,0,1] I need the file to look like this: Output: 1 2 3 1 ...

Why does the variable "YourName" display the input question "What is your name?" instead of showing the user's actual input?

I have developed a program that showcases some preset variables followed by user-input variables. I assumed that after the user enters their name, the print() function would only display the input provided by the user without repeating the question along w ...

The OpenQA.Selenium.Interactions KeyUp function doesn't appear to be working following a KeyDown event

Currently, I am taking on the challenge of inheriting our test automation lead's Test Automation framework. The process has been going smoothly so far, but now I have reached a point where I need to replicate holding down the Shift key, pressing the d ...

What is the process for creating an xpath for hyperlinks with the 'contains text' attribute?

I am in need of creating Xpath for links based on contained text. I have devised the following code to achieve this, however, a scenario arises when there are three links named 'Entity', 'Entity Type', and 'Entity Group'. If I ...

Extracting integer values from strings within a DataFrame column containing colons

I have a DataFrame with the following data: C1 C2 A 2:3:1:7 B 2:1:4:3 C 2:1:1:1 My task is to sort the integers in column C2, while keeping the colons intact. The desired output should be as follows: C1 C2 A 1:2:3:7 B 1:2:3:4 C 1:1: ...

One-To-Many relationship facing issues with Django foreign key integration

Can someone help me with a query that fetches an artist's information and all of their pieces when the artist ID is searched? Essentially, I need a join query between Artist and ArtistPiece. #models.py class Artist(models.Model): name = models.Ch ...

Handling alert, confirm, and popup events in C# using Selenium

Despite extensive research, I have yet to find a solution that addresses the specific issue at hand. Our team is utilizing Selenium with C#. The main problem we are facing is our inability to control alerts, which may be due to their quick disappearance: ...

Link Karate to Selenium

Is it possible to integrate karate and selenium for my testing needs? I have followed instructions on how to call the "JavaApiTest class" and added the necessary karate-core dependency. However, when I attempt to run my tests using the cucumber runner, I e ...

Can Python be used to extract the following text element from HTML?

Hello, I am currently on a quest to locate "FIND THIS" and transform it into "GET THIS" within the HTML code provided below. a= '''<tr> <td colspan="2" width="268"> <span style="width:268px;font-size:1 ...

Guide to integrating post processing features while utilizing youtube-dl within a python script

Is there a way to incorporate post-processing options similar to --embed-thumbnails and --add-metadata while utilizing youtube-dl in a python script? I've gone through the documentation provided, but it doesn't seem to mention any specific &apos ...

Having trouble populating the current date into a web form using Selenium, by retrieving it from an Excel sheet

I already know how to retrieve the current date, but now I need to set it as the previous day's date. My biggest challenge is figuring out how to input this yesterday's date into a web form using Selenium. The form requires information such as s ...

Python Query: Is there a way to modify a list featuring customer information in Python, where each element is limited to either "yes" or "no"?

Imagine this scenario: #inspection of current year team_members = ['julia','mike','stacey', 'alex'] is_team_member_now = ['yes','no','yes','no'] It is evident that Julia and ...

Getting information from a string object using regular expressions in Python

Here is a string that I need to work with: a = '91:99 OT (87:87)' My goal is to split it into separate numbers: ['91', '99', '87', '87'] Since the numerical values can range from 01 to 999, I will be usin ...

Retrieving the DOM of an HTML document in Java

In my current project, I am using headless Chrome as a WebDriver for Selenium tests written in Java. I have noticed potential changes to the DOM when using the headless version of Chrome. Is there a method available to access a copy of the HTML DOM durin ...

Can Selenium be utilized with a headless browser to manage functionalities?

My goal entails running automated tests using Selenium WebDriver through Jenkins, but I encountered an issue where Jenkins was unable to open the browser during the build job. As a workaround, I modified my code to run in headless mode. However, since swit ...

Exploring ways to interact with Span elements using Selenium in Python

Greetings! I am currently attempting to access a specific element called span. My goal is to retrieve this element in a manner that allows me to append it to a list. Each span contains an attribute wordnr="1" or a different number. The objective is to extr ...

Can Python mechanize navigate through links based on URLs and detect the value of the nr parameter?

Apologies for having to pose such a question, but I am finding that the documentation for python's mechanize is quite lacking. Despite my efforts, I cannot seem to figure this out. The only example I could locate for following a link is as follows: r ...

Dropdown menu with multiple selection

Currently, I am working on coding a multi-select feature using Selenium (Java) where the following tasks need to be accomplished: Select multiple options from a dropdown list Click on the "First Selected" button to print out the first selected option fro ...

How can we use Python and Selenium to retrieve the text from HTML that includes the <p> tag?

I have a simple question that I hope you can help me with. I'm not feeling well and struggling to complete my presentation because my brain just isn't functioning properly. Here is the HTML code in question: <p> <b>Postal code:& ...