我正在尝试等待元素与 Python 中的 Selenium 匹配特定数字。它基本上可以假设 0 到 100 之间的每个值。匹配单词是功能性的,但匹配数字有点问题。
代码:
WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element((By.ID, 'price'),"1"))
匹配值 1,但也匹配 10、11、21 和每个包含“1”的数字。 有比这更 pythonic 和更有效的方法吗?
while price != '1':
price = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'price'))).text
谢谢。 Df.
最佳答案
您可以像这样将文本转换为整数值:
PRICE = int(WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'price'))).text)
现在你可以用数字而不是字符串来检查
关于Python Selenium - 带有数字的 text_to_be_present_in_element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67021034/