How to retrieve element values using Selenium WebDriver in a Ruby script

I am facing an issue while trying to set some assertions by extracting a value and then comparing it. However, the statement to extract the value always returns nil.

Expected value:-

<span class="contractSalesPrice.contractSalesPrice">$314,507.30</span>

I have attempted the following methods: -

element1 = browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span")

browser.execute_script("return arguments[0]", element1)

browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span").attribute('value')

browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span").value

What could possibly be causing this issue?

Any help would be greatly appreciated. Thank you in advance.

Abhishek

Answer №1

To retrieve the content inside an HTML element, utilize the #text method.

browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span").text

For extracting attributes of HTML elements, you can use the attribute method. If a specific attribute like 'value' does not exist in the span element, the method will return nil. Refer to the linked documentation for further details.

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

Getting Javascript to automatically start playing audio at specific times during the day

I'm currently working on creating a wallboard system for a restaurant, which requires setting up an alarm to remind the team about specific tasks at three different times every day. While I've already built most of the wallboard using PHP and HTM ...

Adjusting the front size while utilizing the SideNav feature in Materialize

While creating a website using Symfony and Materialize, my client requested to have the menu displayed on the side. I followed the guidelines from and successfully implemented the side menu on the left. However, I am encountering two issues: The first ...

Using Selenium with Python to navigate links by clicking

I would greatly appreciate your assistance with clicking on the link provided below: https://i.sstatic.net/YGhhK.png Even though I attempted to use the code snippet below, it did not work as expected: web.find_element(By.XPATH,'//*[@id="HUI_i_0 ...

Is there a way to transfer a value from my JavaScript game directly into a Flask database?

Currently, I am working on developing a JavaScript game embedded in a website that utilizes a Flask database. For some added context, my goal is to allow users to earn virtual currency, known as Lamocoins, by playing the mini-game. However, I seem to be f ...

Having trouble bringing a 3D object into ThreeJS?

Encountering difficulties while trying to load a 3D object into Three.JS on my website. The 3D images were created in Blender and then exported to .JSON format using MrDoobs exporter addon. edit: This is the exporter I am utilizing - https://github.com/mr ...

What methods can I use to show images at different intervals on a webpage?

I am working on a project where I need to display two images for 5 seconds each at the beginning, followed by images from a different folder displayed for 3 seconds each. Currently, I am using setInterval to display the folder images and trying to use se ...

Updating the default value of a MUI TextField: Step-by-step guide

I am in the final stages of completing my form, but I have encountered an issue when trying to display the current user's name in the defaultValue variable of the TextField from MUI. If the value starts as ""/null, or essentially empty, the ...

Managing nested Angular repeats with counter

In the previous section of my document, I have a presentation layer that effectively organizes information within a shopping cart. This arrangement functions perfectly fine. At the lower portion, I employ the following code to generate form variables whic ...

Locating the XPath for a dropdown menu in an Angular application

Here is the HTML code for a dropdown menu: <div class="margin-bottom"> <select ng-class="{'invalid-select':(selectedItem == '-1' &amp;&amp; submitted)}" class="select-lg select-custom ng-pristine ng-untouched n ...

Enhance your Sequel model by including look-up associations and column aliases

I want to incorporate 'look-up' values from a table that is linked (via two relationships) with the primary table. I am dealing with a database that has been around for a while. Main table: CREATE TABLE foo_table ( id INT PRIMARY KEY NOT NULL ...

Fulfill the promise once all images have finished loading

When I was preloading images, my initial code looked like this: function preLoad() { var deferred = $q.defer(); var imageArray = []; for (var i = 0; i < $scope.abbreviations.length; i++) { imageArray[i] = new Ima ...

The Lightbox containing an IFrame is experiencing flickering issues when links are clicked

I am experiencing a similar issue with this post: How can I resolve flickering in IFrames? Unfortunately, I have yet to find a solution (and I'm worried about receiving negative ratings too :) ). Due to the fact that my website is on an intranet, I ...

Error: The 'str' object is not callable when attempting to access text with driver.page_source() function

I am attempting to scrape tables from a website for various dates using the code below. from selenium import webdriver from selenium.webdriver.chrome.options import Options CHROMEDRIVER_PATH = 'C:/Users/asus/Downloads/chromedriver/chromedriver.exe& ...

Refresh a gif animation when the page is reloaded

I have a website that features a div with a dynamic gif image as the background. The gif animation is set to play only on the initial page load. However, if the page is refreshed or navigated back to the homepage from another page, the animation does not ...

Clicking twice in a row on a map

I am encountering an issue while collecting user input from an infowindow. When I click the 'Save' button in the infowindow to save the input, it inadvertently results in moving my marker on the map by clicking somewhere else. All I really want t ...

Redux-Persist does not save the state in the browser's local storage

My goal is to store specific reducer state in localStorage so that it remains even after a browser refresh. However, when I check the storage, all I see is: "persist:root", "{"_persist":{\"version\":-1,\&qu ...

What is the process to set a Woocommerce checkout field as optional when a checkbox is marked?

I need assistance with customizing the checkout page on Wordpress Woocommerce. Specifically, I want to make the field 'billing_name' not required if the checkbox 'buy_on_company' is checked. Currently, I have successfully hidden ' ...

JavaScript is unable to identify the variable containing parsed JSON

I have been working on coding some gauges for the index page of the R/Shiny dashboards used by our company. The layout consists of several styled divs that link to different R apps. Recently, our executives have shown interest in having fuel-gauge style g ...

Struggling to click on a dynamic link before it times out

Can someone help me with a puzzling issue I can't seem to solve? I am trying to achieve the following: Whenever a link is clicked (for example: mysite.com/blog/blog-article.html), I want to save the href of that link to a variable. Then, in JavaScri ...

Refreshing the page reveals the complete local storage object

I've successfully created a todo list using Vanilla Javascript along with local storage. The todo list includes the following key-value pairs: key: todolist value: [[\"id:0\",\"title:buy groceries\",\"done:false\"], [&b ...