将Python代码转换为Robot Fram

2024-04-29 23:03:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一段python代码需要转换成Robot框架。在

这是python代码。。在

chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "G:/"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "C:/Python27/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

它能在机器人框架下工作吗?在

我对机器人框架知识不多。在


Tags: 代码框架adddefaultdownload机器人robotchromedriver
2条回答

使用Selenium2Library,该代码的直接翻译如下所示:

${chromeOptions}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
${prefs}=    Create Dictionary    download.default_directory    G:/
Call Method    ${chromeOptions}    add_experimental_option    prefs    ${prefs}
${chromedriver}=    Set Variable    C:/Python27/chromedriver.exe
Create Webdriver    Chrome    chrome    executable_path=${chromedriver}    chrome_options=${chromeOptions}
Go To    http://someurl/
[Teardown]    Close All Browsers

此代码依赖于两个库导入-Selenium2Library和Collections。它在调整了你的路径到我的系统后起作用了。在

既然您已经了解Python,那么我将向您介绍许多关于如何在Robot框架中实现Python的问题(这种编码主要是在Python方面)。如果您只想为网页打开一个新的浏览器实例,那么大部分代码可能会被Open Browser关键字简化。要更改Chrome中的设置,请参考解释如何在Robot框架中实现Python代码的问题,或者使用ombre42的建议。在

相关问题 更多 >