Sai prakash
Sai prakash

Reputation: 39

Selenium Java- check if value of results is greater than 900

I got a tag on a webpage which will is a string which contains a number like as "Showing 1 – 40 of 9,814 results for" .

I want to make an assertion that the value is greater than 900.How can it be done.The HTML part of the page is

<span class="_10Ermr">Showing 1-40 of 9,814 results"</span>

Any way of doing thiss?

Upvotes: 0

Views: 1025

Answers (1)

sound wave
sound wave

Reputation: 3537

You can do it in this way with the chromedriver on python. In the code replace chromedriver_path with the path of your driver

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service(chromedriver_path))

driver.get('https://www.flipkart.com/search?q=piraso')

element = driver.find_element(By.XPATH, '//span[contains(text(), "Showing")]')
number_of_results = int(element.text.split('of ')[1].split(' results')[0])
limit = 900
print(f'There are {number_of_results} results, ', end='')
if number_of_results >= limit:
    print(f'higher or equal than the limit {limit}')
else:
    print(f'lower than the limit {limit}')

Upvotes: 1

Related Questions