我正在开发一个Django项目。我使用一个名为test\u seleium\u view()的视图通过seleium启动一个Chrome浏览器。出于演示目的,我的代码如下所示:
你知道吗网址.py你知道吗
# coding=utf-8
from __future__ import unicode_literals, absolute_import
from django.conf.urls import url
from .views import *
urlpatterns = [url(r'^test_seleium$',test_seleium_view,name='test_seleium'),]
试验_选择.py你知道吗
# coding=utf-8
from __future__ import unicode_literals, absolute_import
import time
from django.shortcuts import render_to_response
from selenium import webdriver
def test_seleium_view(request):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--disable-extensions')
CHROME_DRIVER_PATH = r"C:\Program Files (x86)\chromedriver\chromedriver_win32_v2.43.exe"
driver = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH, chrome_options=chrome_options)
driver.get('http://www.google.com')
time.sleep(5)
driver.quit()
return render_to_response('result.html',{'text': "success"})
当我访问Django开发服务器上的http://127.0.0.1:8000/app_name/test_seleium时,一切正常,Seleium启动Chrome浏览器,然后打开http://www.google.com等待5秒钟,然后关闭Chrome浏览器。你知道吗
然后我把这个Django项目带到我的虚拟机(VMware Workstation,win 7 64位安装)上,它安装了Apache和mod\u wsgi,当我访问http://my_vmware_virtual_host_ip:8000/app_name/test_seleium时,它没有启动Chrome浏览器,但是过了一会儿,页面显示“success”文本,就像test\u seleium\u view()已经成功运行一样,还有一个chrome.exewindows 7后台进程。你知道吗
我的环境:
VMware Workstation 15.0.0 build-10134415
Windows 7 64bit on VMware Virtual Machine
Apache 2.4.37 Win64
mod_wsgi 4.6.5+ap24vc14-cp36-cp36m-win_amd64
python 3.6.4 64bit
Django 2.0.7
selenium 3.14.1
chromdriver win32_v2.43,win32_v2.42
我在网上搜索这个问题谷歌网站,但运气不好。你知道吗
我在StackOverFlow.com上发现了一个类似的问题,但没有得到答案。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐