【问题标题】:How to open a Chrome application into Robot using selenium2Library如何使用 selenium2Library 在机器人中打开 Chrome 应用程序
【发布时间】:2018-04-15 12:25:23
【问题描述】:

我正在尝试使用 selenium2Library 在 Robot 中打开我们的 Windows Chrome exe。我尝试使用带有此代码的 Create Webdriver 创建一个 webdriver,但它不起作用。

${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()       sys, selenium.webdriver.chrome.options
${options.add_extension}=        Set_Variable          path/to/extension
Create WebDriver    Chrome    chrome_options=${options}

在 Python 中我这样做......它会在 selenium 中启动我的应用程序。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains

def chromedr():
    chrome_options = Options()
    chrome_options.binary_location = 'C:/Program Files (x86)/InTouch Health/Carestation/Carestation.exe'
    driver = webdriver.Chrome('C:/Program Files (x86)/InTouch Health/Carestation/chromedriver.exe', chrome_options=chrome_options)  
    return driver

如何在 Robot/selenium2Library 中执行此操作?

我能够使用以下代码启动应用程序: ${options}= 评估 sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver 创建 WebDriver Chrome my_alias chrome_options=${options} executable_path=C:/Program Files (x86)/Myapp.exe

【问题讨论】:

  • “不工作”是什么意思?你有任何错误吗?它是否打开了错误的浏览器?机器人会崩溃吗?
  • 我能够使用 ... ${options}= 评估 sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver 创建 WebDriver Chrome my_alias chrome_options= ${options} executable_path=C:/Program Files (x86)/InTouch Health/Carestation/Carestation.exe 但是,我无法将该 webdriver 实例与其他调用(如关闭浏览器)一起使用。如何制作一个独特的网络驱动器(链接到应用程序)并将我的硒/机器人调用定向到它。有没有办法将此对象传递给其他调用或使其成为全局对象?
  • 注意python/ selenium 我在上面的例子中使用了'驱动程序'。
  • 请不要在评论区放代码,无法阅读。如果您需要为您的问题添加更多信息,您可以edit您的问题。你还没有回答我的第一个问题,即“'不工作'是什么意思?
  • 不工作 - 它总是启动 Chrome 浏览器而不是我的 Chomium 应用程序。我想启动一个铬应用程序。我现在能够做到这一点,但现在我似乎无法将 Chomium 应用程序对象与其余的机器人/selenium2library 调用一起使用。这怎么行?

标签: python google-chrome selenium robotframework


【解决方案1】:

用robotframework selenium2library打开chrome

1) 通过 pip 安装 selenium2Library

2) 下载并解压Chrome驱动exe,添加到环境变量中

3) 你可以像下面这样调用 chrome

*** Settings ***
Library    Selenium2Library
*** Variables ***
${SiteUrl}    https://stackoverflow.com
${Browser}    Chrome
*** Test Cases ***
Test
    Open Browser and login
*** Keywords ***
Open Browser and login
    open browser    ${SiteUrl}    ${Browser} 

【讨论】:

  • OP 不想打开 chrome。他们想打开一个铬应用程序,这是不同的。它基于 chrome,但不是 chrome 网络浏览器。
猜你喜欢
  • 2017-03-28
  • 1970-01-01
  • 2012-03-26
  • 2020-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-04
  • 1970-01-01
相关资源
最近更新 更多