简体   繁体   English

在 Python Selenium 中等待某个值大于等于某个数

[英]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.仅当元素值大于或等于 2 时我才需要执行操作,但我不知道如何等待该操作而不仅仅是文本。 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如果您正在寻找元素值属性,请使用text_to_be_present_in_element_value而不是text_to_be_present_in_element

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python-在文本文件中,删除包含大于某个值的数字的行 - Python - In a text file, strip a line containing a number greater than a certain value Python-总和大于或等于值的数字组合 - Python - Combination of Numbers Summing to Greater than or Equal to a Value python 中的“大于”或“等于”与“等于”或“大于” - “Greater than” or “equal” vs “equal” or “greater than” in python 计算 numy.ndarray 中大于某个值的元素数 - Counting number of elements greater than a certain value in a numy.ndarray 如果差值大于某个值,则在列表中保留连续数字 - Keep consecutive number in list if the difference greater than a certain value 计算字典中大于Python中某个数字的值? - Counting values in a dictionary that are greater than a certain number in Python? 如何检查 integer 是否大于 python 中的某个值? - How to check if an integer is greater than another by a certain value in python? 选择大于某个值的Python字典元素 - Selecting elements of a Python dictionary greater than a certain value 列表中大于某个数字的值的数量 - number of values in a list greater than a certain number Python Selenium 查找页面中是否存在属性等于某个值的元素 - Python Selenium Find if Element with an Attribute Equal to a Certain Value Exists in a Page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM