访问客户端计算机上的远程浏览器

时间:2017-03-28 05:27:18

标签: python selenium

我有一个用烧瓶构建的门户,通过它可以初始化selenium并在chrome浏览器中打开给定的Web应用程序。这里的selenium是从python代码运行的,可以访问浏览器。

我在部署应用程序时遇到问题。 我已经在虚拟机VM上部署了门户。 Everthing完美无缺。 但是当我尝试使用虚拟机ip地址从另一台机器访问门户时,门户网站正在渲染但是,Chrome浏览器在虚拟机VM上打开而不是用户的(客户端)机器。这应该可以访问客户端,但这不会按预期发生。

有人可以帮我解决这个问题。请在下面找到代码。

def run_selenium(passed_url):
    browser = request.user_agent.browser
    version = request.user_agent.version and int(request.user_agent.version.split('.')[0])
    platform = request.user_agent.platform
    uas = request.user_agent.string

    if 'OPR' in uas:
        browser = 'Opera'
        driver = webdriver.Opera()
    elif browser == 'chrome':
        browser = 'Chrome'

    #location of chromedriver needed for running seenium on chrome browser. chromedriver is uploaded to github repo
        driver = webdriver.Chrome(conf.CHROME_DRIVER_PATH[0])
    elif browser == 'firefox':
        browser == 'Firefox'
        driver = webdriver.Firefox() 

    driver.get(passed_url) #passing url taken from form
    head_element = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_tag_name('head')) # waiting for page to atleast load <head> element fully so script could be injected
    if head_element:
        print ("injecting script")

        # rawgit.com MaxCDN service used.. js file is at github repo annoletjs/master
        driver.execute_script("!function(){function e(){script=document.createElement('script'),script.type='text/javascript',script.src='//rawgit.com/SSS-Studio-development/annoletjs/tagging/annolet_main.js',document.getElementsByTagName('head')[0].appendChild(script)}($=window.jQuery)?e():(script=document.createElement('script'),script.src='//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js',script.onload=e,document.getElementsByTagName('head')[0].appendChild(script))}();")
        print ("injected")
    return 'annotate'

0 个答案:

没有答案