1

Progress_Bar

I want to handle the progress bar to be stopped after a certain percent let's say 70%. So far I have got the solutions, they all are using .attributeToBe() method. But in selenium 4 I don't have that method present. How can I handle that?

This is the demo link - https://demoqa.com/progress-bar

I have tried to do that using explicit wait like others but I didn't find .attributrToBe() method in selenium 4. Is it possible to do that using loop?

1 Answer 1

1

You can use text_to_be_present_in_element_attribute expected_conditions.
The following code works:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 60)

url = "https://demoqa.com/progress-bar"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.ID, "startStopButton"))).click()
wait.until(EC.text_to_be_present_in_element_attribute((By.CSS_SELECTOR, '[role="progressbar"]'),"aria-valuenow","70"))
wait.until(EC.element_to_be_clickable((By.ID, "startStopButton"))).click()

UPD
For the second page the following code works as well:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 60)

url = "http://uitestingplayground.com/progressbar"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.ID, "startButton"))).click()
wait.until(EC.text_to_be_present_in_element_attribute((By.CSS_SELECTOR, '[role="progressbar"]'),"aria-valuenow","75"))
wait.until(EC.element_to_be_clickable((By.ID, "stopButton"))).click()
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks a ton... It works perfectly. But I am having some issues. For first few times it work's perfectly. Then I tried it for another website and it was not working. Then again I came back to your file and run it and now it also doesn't work. I have faced this type of situations for some other functionalities also. Can you tell me why this happens?
I have tried in this address - uitestingplayground.com/progressbar
You know, based on what you wrote here I can say nothing. I need the exact scenario: what you tried to do, what is your code, on what pages you tried to work. Making some actual debugging possibly will answer your questions, but without all the details I can't help. Also, if you want to ask such question - please ask it as a new, separate question
For the above link I have tried like this... start_button = driver.find_element(By.XPATH, "//button[@id='startButton']") stop_button = driver.find_element(By.XPATH, "//button[@id='stopButton']") progress_bar = driver.find_element(By.XPATH, "//div[@id='progressBar']") ex_wait.until(EC.element_to_be_clickable(start_button)).click() ex_wait.until(EC.text_to_be_present_in_element_attribute(progress_bar, "aria-valuenow", "75")) ex_wait.until(EC.element_to_be_clickable(stop_button)).click()
With slight adjustments to work on the second link the code works as well.. Let me know if I'm missing something
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.