代码之家  ›  专栏  ›  技术社区  ›  DenCowboy

单击按钮[复制]后获取图像的源代码

  •  0
  • DenCowboy  · 技术社区  · 6 年前

    这个问题已经有了答案:

    我有一个python脚本(含selenium),可以在其中单击一个按钮:

    button1 = driver.find_element_by_xpath("//*[@id='test1']")
    button1.click()
    

    当我运行脚本时,它会打开Chrome+我的应用程序并点击按钮。 单击按钮后,按钮的位置将显示一个图像。

    我可以手动检查此图像:

    <img style="" src="//files.qualifio.com/library/xxx.png" class="card_1">
    

    有什么办法可以买到这个吗 src 在python中单击我的 button1 ?

    1 回复  |  直到 6 年前
        1
  •  1
  •   cruisepandey    6 年前

    单击按钮后,引入WebDriver等待图像加载 DOM .

    img = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'img.card_1')))  
    source = img.get_attribute("src")  
    print(source)  
    

    请注意,您必须导入:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC