python-3.x - how to properly call the edge browser with selenium?
问题描述
The target of this project is to automate checking sites with Microsoft edge browser using selenium-python i downloaded the webdriver for the edge legacy from this link and i went for the latest release 17134 extracted it with out any problems now lets say i want to visit facebook in an automated way with firefox using the geckodriver
firefox code sample with selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
# setting up headless option for faster execution
options = Options()
options.headless = True
browser = (webdriver.Firefox(options=options))
browser.get('https://www.facebook.com/')
but when I try to use Microsoft edge that is built in windows 10 I get an attribute error
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.edge.options import Options
options = Options()
options.headless = True
#browser = webdriver.edge(options=options)
browser = webdriver.edge()
ps : when I uncomment this part (browser = webdriver.edge(options=options)) I get module not found error
what is the right way to call Microsoft edge browser , or what I am doing wrong
解决方案
当我使用 Edge 并尝试使 Edge 无头时。我也发现很难做到这一点,因为 Chrome 的轻微变化。我参考了官方文档并获得了官方解决方案。除了 selenium,还需要安装msedge-selenium-tools
,pip install 即可pip install msedge-selenium-tools
。Edge
并在 msedge 工具中使用Class。就像:
from msedge.selenium_tools import Edge
driver = Edge(executable_path='where')
如果我们想让 Edge 无头,我们需要使用EdgeOptions
selenium.webdriver 不提供的 Class。selenium.webdriver 只为我们提供了 ChromeOptions、FirefoxOptions 和 Ie 的。EdgeOptions 在一个单独的包中msedge.selenium_tools
。然后我们添加参数,就像我们在 Firefox 或 Chrome 上所做的那样。在此之前,我们需要将属性use_chromium设置为 True。整个代码:
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
# make Edge headless
edge_options = EdgeOptions()
edge_options.use_chromium = True # if we miss this line, we can't make Edge headless
# A little different from Chrome cause we don't need two lines before 'headless' and 'disable-gpu'
edge_options.add_argument('headless')
edge_options.add_argument('disable-gpu')
driver = Edge(executable_path='where', options=edge_options)
希望能帮助到你。对不起,我的尴尬解释。
推荐阅读
- plsql - Oracle SQL Developer 和代码/行更改指示器
- javascript - 在外面关闭模态窗口并在里面有可点击的链接
- job-scheduling - 轮班最少护士
- sql - 是否可以将表别名附加到列名以找出列的来源?
- python - 根据索引从字典python中删除一个元素
- javascript - 我想要一个粘性标题中的按钮在向下滚动时变为红色
- ionic-framework - Ionic 4:离子标签栏未显示在 Chrome 中
- java - 工具栏上的叠加元素
- html - 问题:用 HTML/CSS 在计算器上创建一个按钮(仅限设计)
- python - 尝试使用 Python 正确缩进和缩进 asp 代码