Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

python - Running Edge browser on Selenium in MacOs (Catalina)

can someone help to run it one Python & MacOS ( catalina?)

I've tried to use it on windows environment, works as expected, but unfortunately, cannot do it on mac. it seems that some configuration is needed

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.firefox.options import Options as options
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By



class Website:
    def __init__(self):

      self.driver = webdriver.Edge(executable_path='/Users/dannyk/Downloads/msedgedriver')

    def reach_web_docker(self):
        self.driver.maximize_window()
        self.driver.get('http://127.0.0.1:9080/')



if __name__ == '__main__':
    reg1 = Website()
    reg1.reach_web_docker()

And i get the following error, which unfortunately doesnt really explain what the issue is

>> runfile('/Users/dannyk/PycharmProjects/new_prj/t1.py', wdir='/Users/dannyk/PycharmProjects/new_prj')
/Users/dannyk/PycharmProjects/new_prj/t1.py:16: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  self.driver = webdriver.Edge(executable_path='/Users/dannyk/Downloads/msedgedriver')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"
", file, 'exec'), glob, loc)
  File "/Users/dannyk/PycharmProjects/new_prj/t1.py", line 57, in <module>
    reg1 = Website()
  File "/Users/dannyk/PycharmProjects/new_prj/t1.py", line 16, in __init__
    self.driver = webdriver.Edge(executable_path='/Users/dannyk/Downloads/msedgedriver')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/edge/webdriver.py", line 65, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.EDGE['browserName'], "ms",
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 79, in __init__
    RemoteWebDriver.__init__(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 183, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 280, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 349, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 240, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found
Stacktrace:
0   msedgedriver                        0x000000010e547ef9 msedgedriver + 12562169
1   msedgedriver                        0x000000010e486a23 msedgedriver + 11770403
2   msedgedriver                        0x000000010da59d2d msedgedriver + 1101101
3   msedgedriver                        0x000000010d99465e msedgedriver + 292446
4   msedgedriver                        0x000000010d993e82 msedgedriver + 290434
5   msedgedriver                        0x000000010d9954fd msedgedriver + 296189
6   msedgedriver                        0x000000010d991cb3 msedgedriver + 281779
7   msedgedriver                        0x000000010d96ac2d msedgedriver + 121901
8   msedgedriver                        0x000000010d96bc25 msedgedriver + 125989
9   msedgedriver                        0x000000010e4e109f msedgedriver + 12140703
10  msedgedriver                        0x000000010e4f39da msedgedriver + 12216794
11  msedgedriver                        0x000000010e4f3769 msedgedriver + 12216169
12  msedgedriver                        0x000000010e49e539 msedgedriver + 11867449
13  msedgedriver                        0x000000010e4f3f63 msedgedriver + 12218211
14  msedgedriver                        0x000000010e4ca783 msedgedriver + 12048259
15  msedgedriver                        0x000000010e510c24 msedgedriver + 12336164
16  msedgedriver                        0x000000010e551697 msedgedriver + 12600983
17  libsystem_pthread.dylib             0x00007fff69056109 _pthread_start + 148
18  libsystem_pthread.dylib             0x00007fff69051b8b thread_start + 15
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

so, to answer it , and thanks to @Deepak-MSFT , that worked.

all was needed two things:

  1. send the driver path (in my case, i was needed to move it locally, and send abs path

  2. send capabilities. Also, i've removed all the capabilities, and put an empty dictionary.

here's the code.

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.firefox.options import Options as options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By


desired_cap = {
}

class Website:
    def __init__(self):

      self.driver = webdriver.Edge(executable_path='/Users/dannyk/PycharmProjects/new_prj/msedgedriver',capabilities=desired_cap)

    def reach_web_docker(self):
        self.driver.maximize_window()
        self.driver.get('http://127.0.0.1:9080/')


if __name__ == '__main__':
    reg1 = Website()
    reg1.reach_web_docker()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...