硒铬只能打开一次

时间:2018-09-26 02:29:28

标签: python selenium

我有两个使用Selenium来运行不同任务的文件。

我可以分别运行它们(只能运行一个),但是如果我想同时运行两个文件或一个一个地运行它们,则可以。第二个将崩溃,并显示以下错误。

 File "site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __ini
__
 File "site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __in
t__
 File "site-packages\selenium\webdriver\remote\webdriver.py", line 251, in star
_session
 File "site-packages\selenium\webdriver\remote\webdriver.py", line 320, in exec
te
 File "site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in c
eck_response
elenium.common.exceptions.WebDriverException: Message: unknown error: Chrome fa
led to start: crashed
 (unknown error: DevToolsActivePort file doesn't exist)
 (The process started from chrome location C:\Program Files (x86)\Google\Chrome
Application\chrome.exe is no longer running, so ChromeDriver is assuming that C
rome has crashed.)
 (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c19
e),platform=Windows NT 6.1.7601 SP1 x86_64)

代码非常简单,例如:

u = getpass.getuser()

chrome_options = Options()
## Add the user information
chrome_options.add_argument('user-data-dir=C:\\Users\\%s\\AppData\\Local\\Google\\Chrome\\User Data' % (u))

## SF Case page
source = "https://na66.salesforce.com/500?fcf=00BC0000008hfCI"
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get(source)

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

那是因为我们同时使用相同的配置文件。 以下面的代码为例:

不工作:

h1="https://www.google.com"
h2="https://www.163.com"
d1= webdriver.Chrome(chrome_options=chrome_options)
d1.get(h1)

d2= webdriver.Chrome(chrome_options=chrome_options)
d2.get(h2)

工作:

h1="https://www.google.com"
h2="https://www.163.com"
d1= webdriver.Chrome(chrome_options=chrome_options)
d1.get(h1)

d2= webdriver.Chrome()
d2.get(h2)

原因和解决方案可以在this中看到。