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

火山引擎 最新活动