Tips for extracting a number from a div block with xPath

Recently, I started learning about xPath and encountered a challenging task. I need to extract the text "22 973 ₴" from this code snippet. Can anyone advise me on how to achieve this?

<div class="col search_price discounted responsive_secondrow">
   <span style="color: #888888;"><strike>25 758₴</strike></span><br>22 973₴                    
</div>
           

Answer №1

If you're looking to extract the value 22 973₴, you can utilize the following xPath query:

//div[contains(@class,'discounted')]/text()[2]

Implementation in code:

To retrieve the value using Selenium and Java:
driver.findElement(By.xPath("//div[contains(@class,'discounted')]/text()[2]")).getText();

Answer №2

If you are utilizing python-Selenium, it is not possible to utilize text() in xpath for it to function properly in Selenium, as Selenium uses xpath v1.0

Kindly make use of the following code:

price = driver.find_element(By.XPATH, "//div[contains(@class,'col search_price discounted responsive_secondrow')]")
p = price.get_attribute('innerText').split('\n')
print(p[1])

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 accessing or adding source code in IntelliJ 12

After creating a new project in IntelliJ version 12, which is a Maven module, I made sure to select the autoscroll options from the IDE. However, when I hover over WebDriver using Ctrl Q, it keeps prompting me to download or attach the source code. Despite ...

Learn how to input data into two fields using the send.keys method in Selenium with Python, even if they share the same

Attempting to input a password field and a confirm password field. Both fields do not have an ID and share the same xpath, with the only difference being that the first field labeled "Enter password" has [1] and the second field labeled "Confirm password" ...

Running test classes concurrently can be achieved by combining PHPUnit and Selenium Webdriver

Using PHPUnit and Selenium 2 Webdriver, I am automating tests for my web application. Currently, I have multiple test classes that run sequentially. But I believe they could be run simultaneously in separate browser instances, resulting in a faster testin ...

"Encountering a Glitch in Google Translate Using Python and

I can't figure out where the issue lies. I followed these sources: https://medium.com/python/python-selenium-mod%C3%BCl%C3%BC-kullan%C4%B1m%C4%B1-ders-1-36983185164c https://www.youtube.com/watch?v=olOswIyeRlY Code from selenium import webdriver from ...

After a simple call to navigate() in WebDriver, IE forgets all window handles

I have been searching for solutions to my problem, but I've found nothing that works. Whenever I start IEServerDriver and try to navigate to a URL that redirects to HTTPS, some browsers on certain test machines cause me to lose all windowhandles. My W ...

Is it possible to implement reusable test steps in nightwatch.js?

My goal is to develop reusable components for my nightwatch.js tests. For example, logging in and logging out of the web application. What would be the most effective approach or pattern for creating these steps in a way that is reusable? ...

What sets apart adjusting window size through Options versus using the set_window_size method?

Seeking guidance on adjusting window size in Selenium. Discovered a helpful solution at How to set window size in Selenium Chrome Python rom selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_ar ...

Identifying elements using xpath - Streamlined Xpath Techniques

I successfully found the element using the xpath copied directly from the code. Can someone assist me in creating a simpler xpath for the following code snippet, which is fully functional! WebElement oCheckbox = myDriver.findElement(By.xpath(".//*[@id=&ap ...

Selenium encounters difficulties accessing the Gitlab login page

Currently, I am running an automated test using Java (8), Selenium (4), and Chromedriver (98.0). The test focuses on logging into a website with various third-party accounts, including GitLab. Unfortunately, the test consistently stalls when attempting t ...

Issue with Selenium script implementation

I am facing a challenge as a writer. I have created a task as an admin and assigned it to myself, but now I am having trouble locating the specific task in the list of 10 tasks displayed on the page. The task could be on the first or second page, and I nee ...

Unable to create a new instance of the WebDriver for class org.openqa.selenium.remote.RemoteWebDriver

Encountering an error while attempting to run in Sauce Labs. Unsure of the issue and how to resolve it. Any assistance would be greatly appreciated. Note: A secure remote tunnel is set up and running smoothly. Command: mvn clean verify -Dwebdriver.driver ...

What is the process of updating the default version of Firefox using Selenium webdriver in Ruby?

I successfully changed the Firefox version I am using to 33.1 using this code. However, I want to make the current version the default without having to add extra code to each script. path='C:\Program Files (x86)\Mozilla Firefox\firefo ...

Detecting the locally installed browsers with Selenium PHPUnit

As I run Selenium through PHPUnit for my current project, involving multiple developers and machines, I'm looking to have the browser selection for tests be based on what browsers are installed on the local machine. For instance, running tests on Wind ...

Is it possible to use Selenium for testing mobile web applications?

Seeking guidance on how to conduct automated testing using Selenium or another Ruby-aware tool for Android devices (Android Browser) and iPhone/iPad (Safari for iOS). Any recommendations or strategies would be appreciated. ...

No element detected with Selenium VBA

I am currently exploring the use of VBA and Selenium to automate data entry from Excel for my work. However, I am still in the early stages and facing a challenge where I need to click on Reserve / Contact Guest in order to progress with writing my code. ...

In attempting to utilize XPath for clicking a button through C# Selenium, I encounter issues with its functionality

Having trouble clicking a button using its XPath in C# Selenium. I encountered an error message in C# and as a beginner on this platform, I'm unsure of what to do next. Any guidance or assistance would be greatly appreciated. https://i.stack.imgur.co ...

What is the process for choosing a document from a Google Drive pop-up selection window using Python's selenium module?

Currently, I am working on a beta proof of concept automation project where my main focus is entering a Google Drive pop-up window and selecting a specific document to submit. The appearance of the popup window can be seen below: https://i.stack.imgur.com ...

The function in Python Selenium for sending text can send only a portion of the text

I have been working on automating tests using Python Selenium with chromedriver. Here is a snippet of the code I have been working on: inputElement.send_keys(2356785) try: print("Attempting to use ENTER key") submit ...

Having trouble connecting with the SafariDriver extension

During my e2e testing of an AngularJS web-app using protractor on Chrome and Firefox, I encountered an issue when attempting to include Safari in the array. The error message displayed was: "Unable to establish a connection with the SafariDriver extension ...

Is it possible to extract data from tables that have the 'ngcontent' structure using Selenium with Python?

Scraping basic tables with Selenium is a simple task. However, I've been encountering difficulties when trying to scrape tables that contain "_ngcontent" notations (as seen at "https://material.angular.io/components/table/overview"). My goal is to con ...