Tuesday, October 26, 2021

selenium 2 conditional wait


when label is 100%, print
#logs
DevTools listening on ws://127.0.0.1:59251/devtools/browser/50b6c55d-da1f-433c-85bf-ca7f40c0543a
progress bar is 100%

#main.py
import os
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

os.environ['PATH'] += r"C:/Users/zchen/PycharmProjects/selenium"
driver = webdriver.Chrome()
driver.get("https://www.w3schools.com/howto/howto_js_progressbar.asp")
driver.implicitly_wait(30)
runButton = driver.find_element(By.XPATH, '//button[text()="Run"]')
runButton.click()

WebDriverWait(driver, 30).until(
    EC.text_to_be_present_in_element(
        (By.ID, 'prlabel'),
        '100%'
    )
)

print('progress bar is 100%')

reference:

No comments:

Post a Comment