我正在尝试读取网页的控制台输出,特别是我需要使用 RF 和 Selenium 进行 POST-GET-PUT ajax 调用。我在网上找到了一些帮助,但似乎无法使其发挥作用。我的Python脚本是:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def get_logs2(driver):
# enable browser logging
#d = DesiredCapabilities.CHROME
#d['goog:loggingPrefs'] = { 'browser':'ALL' }
#driver = webdriver.Chrome(desired_capabilities=d)
# load the desired webpage
#driver.get(driver.current_url)
a = driver.get_log('browser')
# print messages
for entry in driver.get_log('browser'):
print(entry)
print("finished")
return a
在网页上完成一些操作后,我从 RF 调用此脚本。因此,我需要将页面在我执行操作后的状态准确地传递给此函数。为此,我这样做:
${seleniumlib}= Get Library Instance SeleniumLibrary
Log ${seleniumlib._drivers.active_drivers}[0]
${message} = Get Logs2 ${seleniumlib._drivers.active_drivers}[0]
我得到结果和空消息,但我知道控制台不为空。你能帮我吗?谢谢。
这是一个完全使用 Robot Framework 的解决方案,没有额外的用户库。
逻辑是一样的。
- 设置正确的浏览器功能以启用日志记录。
- 然后使用
Get Library Instance
关键字来检索 webdriver 实例。
- 致电
get_log('browser')
在网络驱动程序实例上。
*** Settings ***
Library SeleniumLibrary
*** Variables ***
&{browser logging capability} browser=ALL
&{capabilities} browserName=chrome version=${EMPTY} platform=ANY goog:loggingPrefs=${browser logging capability}
*** Test Cases ***
Browser Log Cases
Open Browser https://stackoverflow.com Chrome desired_capabilities=${capabilities}
${log entries}= Get Browser Console Log Entries
Log ${log entries}
[Teardown] Close All Browsers
*** Keywords ***
Get Browser Console Log Entries
${selenium}= Get Library Instance SeleniumLibrary
${webdriver}= Set Variable ${selenium._drivers.active_drivers}[0]
${log entries}= Evaluate $webdriver.get_log('browser')
[Return] ${log entries}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)