简体   繁体   中英

Waiting for a value to be greater than or equal to a certain number in Python Selenium

i'm trying to make a program that waits for a certain value to be greater than or equal to a certain number and then do some actions.

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.minimize_window()

driver.get("https://www.awstats.io/mining/pools/kavian")

try:
    element= WebDriverWait(driver, 30).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/div[3]/div[2]/table[1]/tbody/tr/td[3]'),'2.'))
    print(int(element))
except:
    print('time elapsed')
    pass

I need to execute an action only if the element value is greater or equal than 2 but i have no idea on how to wait for that instead of just the text. Any tips?

Maybe this is not the best approach, but you can use something like this:

element = 0
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[3]/div[2]/table[1]/tbody/tr/td[3]')))
for x in range(10): 
  element = driver.findelement_by_xpath('/html/body/div[3]/div[2]/table[1]/tbody/tr/td[3]').text    
    if(int(element) >= 2):
       print(int(element) >= 2)
    else:
      time.sleep(1)
if(int(element) < 2):
  print(Couldn't find expected value inside the element)

The code above is for element text value.
In case you are looking for element value attribute use text_to_be_present_in_element_value instead of text_to_be_present_in_element

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM