Robotframework 如何在robot框架中处理动态表

Robotframework 如何在robot框架中处理动态表,robotframework,Robotframework,我使用标记创建了一个表,其中包含一组行,每行都有列,比如col1、col2、col3、col4、col5和col6 col1到col5有一些值,col6是编辑按钮 根据作为参数发送的Col1到col4值,我必须单击Edit按钮,然后执行一些操作 我知道如何通过SeleniumWebDriver处理这个问题 示例代码如下所示: // Find Table Web Element WebElement tableEle = driver.findElement(By.xpath("\\div

我使用
标记创建了一个表,其中包含一组行,每行都有列,比如col1、col2、col3、col4、col5和col6

col1到col5有一些值,col6是编辑按钮

根据作为参数发送的Col1到col4值,我必须单击Edit按钮,然后执行一些操作

我知道如何通过SeleniumWebDriver处理这个问题

示例代码如下所示:

    // Find Table Web Element
WebElement tableEle = driver.findElement(By.xpath("\\div[@class='ui-grid-canvas']")

     // Using Table WebElement find the list of Rows
    List<WebElement> tableRows = tableEle.findElements(By.xpath("\\div[@ui-grid-row='row']"))

//Loop through each Row 
    for(int rnum=0;rnum<tableRows.size();rnum++)
        {
        //Get the Columns for each row
        List<WebElement> tableColumns=tableRows.get(rnum).findElements(By.xpath("div[@role='gridcell']\div"));
         count=0;
         //loop through each column
        for(int cnum=0;cnum<tableColumns.size();cnum++)
        {
            //verify the each column value with req values array , if matches increase the count otherwise come out of columns for loop
if((columns.get(cnum).getText()).equalsIgnoreCase(ReqValues[cnum]))
               {
                    count++;
               }
               else
                {
                    break;
                }
            // count is equal to column size -1 then matched all records click on the last column where edit icon exist and come out of rows for loop
           if(count ==( tableColumns.size()-1))
           {
                columns.get((tableColumns.size())-1).click();
                   break;
           }
        }
        }
//查找表Web元素
WebElement tablele=driver.findElement(By.xpath(\\div[@class='ui-grid-canvas']))
//使用TableWebElement查找行列表
List tableRows=tablele.findElements(By.xpath(\\div[@ui grid row='row']))
//循环遍历每一行

对于(int rnum=0;rnum我通过创建一个python关键字并在robot框架代码中使用它来解决这个问题

以下是机器人框架代码:

    @{elemnts}=    Get Webelements    ${table_rows_xpath}

    #iterate for each row
    : FOR    ${row}    IN    @{elemnts}
    \    @{columns}=    CustomLibrary.Get Webelements By Element    ${row}    ${from_parent_row_to_columns_xpath}
    \    ${status}=    Traverse through columns        @{columns}
    \    Run Keyword If    ${status}=="SUCCESS"    Click on Edit icon and Exit Loop    @{columns}


Traverse through columns
    [Arguments]    @{columns}
    ${length}    Get Length    ${verify_values}
    Set Test Variable    ${count}    0
    ${index}    Set Variable     0
    : FOR    ${col}    IN    @{columns}
    \    ${value}=    Get Text    ${col}
    \    Run Keyword If    '${value}'== '${verify_values[${index}]}'    Increment Count    ELSE    Exit For Loop
    \    ${index}=    Evaluate    ${index}+1
    \    Run Keyword If    ${length} == ${count}   Set Status SUCCESS and Exit 


Click on Edit icon and Exit Loop
    [Arguments]    @{columns}
    ${length}    Get Length    ${columns}
    ${length}=    Evaluate    ${length}-1
    Click Element    @{columns}[${length}]
    Exit For Loop    
python代码

def get_webelements_by_element(webElement, locator):
values = locator.split("=",1)

    locateBy = values[0]
    locator = values[1]

    if(locateBy =="name"):
        ele = webElement.find_elements_by_name(locator)
    elif(locateBy =="link"):
        ele = webElement.find_elements_by_link_text(locator)
    elif(locateBy =="partial link"):
        ele = webElement.find_elements_by_partial_link_text(locator)
    elif(locateBy =="tag"):
        ele = webElement.find_elements_by_tag_name(locator)
    elif(locateBy =="css"):
        ele = webElement.find_elements_by_css_selector(locator)
    elif(locateBy =="xpath"):
        ele = webElement.find_elements_by_xpath(locator)    

    return ele

你的第一个for循环将是as is,第二个for循环可以进入robotframework关键字,该关键字将在first for循环中调用。rest在robot中看起来非常可能。第一个相同,我可以使用
Get Element
关键字,但下一个基于元素,我们如何使用
Get Elements
关键字?,我认为e> Get Elements
关键字类似于
driver.findElements
,但不是在
webElement.findElements
上,我想知道您是否尝试过使用Get table cell?下面是它的用法示例Hi waman,如果表是使用
table
标记创建的,那么这些方法会起作用,但在我的例子中,它是使用
标记创建的,所以我在其他方法中,它不会带来任何好运?比如获取元素并对其进行迭代?