首页 > 解决方案 > 如何在Robot框架中将元素的html表转换为Arraylist元素

问题描述

我试图获取 HTML 表值的元素并尝试将其拆分为 ArrayList 元素(行)示例:

在此处输入图像描述

我曾经获取 Webelements,结果是:

@{Row5} = [ <selenium.webdriver.firefox.webelement.FirefoxWebElement (session="15a5573d-6584-4669-bbce-1b4bf61f3298", element="f175bac9-2f59-4e8b-a24b-2e098aea47a7")> ]

List variable '@{Row5}' has no item in index 2.

我通过“获取表格单元格”获取元素,然后我可以获取值的字符串,但我无法选择此表中的复选框(第 6 列)。

标签: pythonarraylistrobotframework

解决方案


最后,我知道如何通过 xpath 的 Set Variable 选择复选框:

Validate Data4Click
     [Arguments]     ${row}
     ${CPid}=    Get Table Cell    ${AddN_C.value_table}     ${row}  3
     AddnoteChxboxColumn    ${row}
     [Return]    ${CPid}

AddnoteChxboxColumn
     [Arguments]     ${row}
     ${xpathAddnote_column}=   Set Variable  xpath=/html/body/form/table/tbody/tr/td/table[2]/tbody/tr[5]/td/table/tbody/tr/td[2]/table/tbody/tr/td/table[1]/tbody/tr[${row}]/td[6]/input[4]
     Validate chkbox has selected    ${xpathAddnote_column}

Validate chkbox has selected
     [Arguments]     ${locate}
     Wait Until Element Is Visible    ${locate}    ${timeout}
     Checkbox Should Not Be Selected     ${locate}
     Select checkbox   ${locate}
     Checkbox Should Be Selected     ${locate}

推荐阅读