You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Selenium Python配置Edge(Chromium)浏览器禁用图片

Disable Image Loading in Selenium for Microsoft Edge (Python)

Got it! Since modern Microsoft Edge is built on the Chromium engine, the method to disable image loading is very similar to Chrome—you just need to use Edge's specific options class instead of Chrome's. Here's how to update your existing Edge code to achieve this:

Step-by-Step Solution

  • Set content preferences to block images: Use the same prefs dictionary you know from Chrome, which tells the browser to block image content.
  • Integrate with EdgeOptions: Add these preferences to your Edge options configuration, along with any existing settings you need (like your web notification toggle).
  • Initialize the driver with the configured options.

Full Working Code

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.edge.options import Options

# Configure Edge options
options = Options()

# Disable image loading: 2 = Block images, 1 = Allow, 0 = Default
image_prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", image_prefs)

# Keep your existing web notification setting (1 = enabled)
options.set_capability("dom.webnotifications.enabled", 1)

# Launch Edge with the configured options
driver = webdriver.Edge(options=options)

# Your existing navigation and interaction code
driver.get("https://www.mywebsite.com/")
daftar = driver.find_element_by_xpath('//*[@id="header-main-wrapper"]/div[2]/div[5]/button[1]')
actions = ActionChains(driver)
actions.click(daftar).perform()

Key Notes

  • The value 2 in the preferences dictionary specifically tells the browser to block all image content. If you ever need to re-enable images later, just change it to 1 (allow) or remove the preference entirely.
  • You don't need to use options.to_capabilities() anymore with newer Selenium versions—passing the options object directly to webdriver.Edge() works perfectly and is cleaner.

内容的提问来源于stack exchange,提问作者Kama Adhitia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 16:32:32