机器人框架-获取当前日期-未找到名称为'='的关键字

时间:2020-08-03 12:59:12

标签: python-2.7 datetime robotframework

我正在尝试使用当前时间更新一个Excel文件上的列。

要实现此目的,我正在使用import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.Timer; public class Testing { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Testing t = new Testing(); } }); } private Timer timer; private JFrame frame; private JButton btn; private int timePassed; public Testing() { frame = new JFrame(); timer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { timePassed++; updateTimeOnButton(); } }); btn = new JButton("START"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (timer.isRunning()) { timer.stop(); btn.setText("START"); } else { timePassed = 0; timer.start(); updateTimeOnButton(); } } }); frame.getContentPane().add(btn); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setSize(new Dimension(300, 300)); } private void updateTimeOnButton() { btn.setText(timePassed + " seconds"); } } 库中的Get Current Date关键字,并将其存储到下面脚本中的标量DateTime

${datetime}

我遇到以下错误:

*** Settings *** Default Tags Download_File Library SeleniumLibrary Library ExcelLibrary Resource Userdefinedkeywords.txt Library DateTime Run Keyword If ${countt}>0 Run Keywords Click Element xpath://[@id="fileSubmit"]/div[1]/img ... AND Open Excel D:\\RPA\\Demo\\Excelx.xls ... AND Put String To Cell Test 2 ${countd} ZIP FILE ... AND Save Excel D:\\RPA\\Demo\\Excelx_DONE.xls ... ELSE IF ${countt2}>0 Run Keywords Click Element xpath://*[@id="plsAttachGrid_0_1"]/img ... AND ${datetime}= Get Current Date ... AND Open Excel D:\\RPA\\Demo\\Excelx.xls ... AND Put String To Cell Test 2 ${countd} SINGLE FILE ... AND Put String To Cell Test 3 ${countd} ${datetime} ... AND Save Excel D:\\RPA\\Demo\\Excelx_DONE.xls ... ELSE Run Keywords Open Excel D:\\RPA\\Demo\\Excelx.xls ... AND Put String To Cell Test 2 ${countd} NO FILE ${countd}= Evaluate ${countd}+${1}

代码部分运行后:

FAIL : No keyword with name '=' found.

代码有什么问题? 预先感谢

1 个答案:

答案 0 :(得分:4)

您无法在“运行关键字是否为”内进行变量分配-它仅运行关键字,而这正是框架抛出错误的原因。

Run Keyword If    ${countt}>0    Run Keywords    Click Element    xpath://[@id="fileSubmit"]/div[1]/img
# skipped lines
    ...    AND    ${datetime}=    Get Current Date
    ...    AND    # skipped lines

到达该行时,它将尝试运行带有参数“ Get Current Date”的关键字${datetime}=,并失败。