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?

Prophet
  • 32,350
  • 22
  • 54
  • 79

1 Answers1

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()
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • 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? – Tanvir Ahmed Dec 08 '22 at 12:54
  • I have tried in this address - http://uitestingplayground.com/progressbar – Tanvir Ahmed Dec 08 '22 at 13:01
  • 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 – Prophet Dec 08 '22 at 13:01
  • 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() – Tanvir Ahmed Dec 08 '22 at 13:05
  • With slight adjustments to work on the second link the code works as well.. Let me know if I'm missing something – Prophet Dec 08 '22 at 13:07
  • I have done the same as yours but I don't know why It doesn't work in my machine. The progress reach 100% and then a TimeoutException is raised for the progress bar element. I have updated the browser and the chrome driver also. Can It be a bug of the web driver or bug of pycharm? For the both website progress bar is reaching 100% and raising exceptions though at the first attempt the progress bar stopped at 70% for one time only. – Tanvir Ahmed Dec 09 '22 at 06:10
  • Well, I don't know. I don't believe this could be a bug with driver or pycharm. More likely to be - you have some additional code that I do not have or you changed something, not used exactly what I used. These are only 3 simple code lines. – Prophet Dec 09 '22 at 09:43
  • I have used the same code of yours, just edited the locators of the elements using XPATH and nothing else. But It didn't work. Then I took a new project and then copy pasted the same lines in a new file and ran it and It ran finally. I don't know why this happened. I have faced this issue before also. – Tanvir Ahmed Dec 10 '22 at 06:00
  • Sounds strange, but again. since I did not see what you do and how I can't know what happened on your, but since finally it worked it's OK :) – Prophet Dec 10 '22 at 16:38