使用 selenium 的自动化,无法在不同版本的列表中搜索

Automation using selenium, unable to search within lists of different versions

我想搜索特定版本的 seldon-core (1.7.0) (https://pypi.org/) . I have reached (using selenium) till the release history page(https://pypi.org/project/seldon-core/#history) 但无法搜索特定版本 (1.7.0)。

我想在整个列表(所有版本都包含在列表中)中搜索版本匹配项。
PS:该列表有 div id 作为“历史”,而且它还有子类,其中提到了版本号。

搜索特定版本的 seldon-core,例如1.7.0seldon-core . PyPI History page you need to induce for the visibility_of_all_elements_located() and you can use the following 内:

  • 代码块:

    driver.get("https://pypi.org/project/seldon-core/#history")
    text = "1.7.0"
    if(text in element.text for element in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "p.release__version")))):
        print("Version found")
    else:
        print("Version not found")
    driver.quit()
    
  • 控制台输出:

    Version found
    

更新

如果您想在列表中搜索版本匹配,您可以使用:

  • 代码块:

    driver.get("https://pypi.org/project/seldon-core/#history")
    versions_search = ["1.8.2", "1.9.2", "1.7.0"]
    versions_available = [element.text for element in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "p.release__version")))]
    if any(x in versions_search for x in versions_available):
        print("Version match found")
    else:
        print("Version match not found")
    driver.quit()
    
  • 控制台输出:

    Version match found