Python 3.x 使用Robot框架对项目进行迭代的问题
我正在使用带有FOR循环的Robot框架编写一个关键字,以迭代出现在第一个下拉列表中的所有值,并逐个进行选择。循环正在工作,但无法迭代以选择索引 网站:Python 3.x 使用Robot框架对项目进行迭代的问题,python-3.x,robotframework,Python 3.x,Robotframework,我正在使用带有FOR循环的Robot框架编写一个关键字,以迭代出现在第一个下拉列表中的所有值,并逐个进行选择。循环正在工作,但无法迭代以选择索引 网站: ${Xpath_Departure_DropDown}= "xpath://*[starts-with(@class,'container')]//select[@name='fromPort']" ${Xpath_Departure_DropDown_Options}= "xpath://select[@nam
${Xpath_Departure_DropDown}= "xpath://*[starts-with(@class,'container')]//select[@name='fromPort']"
${Xpath_Departure_DropDown_Options}= "xpath://select[@name='fromPort']/option"
KW_14: Choose your departure city Drop Down:
@{All_Items_In_Drop_Down}= Get List Items ${Xpath_Departure_DropDown} values=True
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
${Length_Of_Lists_Items}= get length ${All_Items_In_Drop_Down}
FOR ${Index} IN RANGE ${Length_Of_Lists_Items}
LOG ${Index} html=true
Click Element ${Xpath_Departure_DropDown}
sleep 2 seconds
run keyword and continue on failure Select From List By Index ${Xpath_Departure_DropDown_Options}[${Index}]
sleep 2 seconds
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
END
(选择您的出发城市:)
测试用例是:
${Xpath_Departure_DropDown}= "xpath://*[starts-with(@class,'container')]//select[@name='fromPort']"
${Xpath_Departure_DropDown_Options}= "xpath://select[@name='fromPort']/option"
KW_14: Choose your departure city Drop Down:
@{All_Items_In_Drop_Down}= Get List Items ${Xpath_Departure_DropDown} values=True
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
${Length_Of_Lists_Items}= get length ${All_Items_In_Drop_Down}
FOR ${Index} IN RANGE ${Length_Of_Lists_Items}
LOG ${Index} html=true
Click Element ${Xpath_Departure_DropDown}
sleep 2 seconds
run keyword and continue on failure Select From List By Index ${Xpath_Departure_DropDown_Options}[${Index}]
sleep 2 seconds
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
END
第一个将选择值为“Paris”的零指数,然后选择值为“Philadelphia”的第一个指数,依此类推,直到第六个指数
XPATH:
${Xpath_Departure_DropDown}= "xpath://*[starts-with(@class,'container')]//select[@name='fromPort']"
${Xpath_Departure_DropDown_Options}= "xpath://select[@name='fromPort']/option"
KW_14: Choose your departure city Drop Down:
@{All_Items_In_Drop_Down}= Get List Items ${Xpath_Departure_DropDown} values=True
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
${Length_Of_Lists_Items}= get length ${All_Items_In_Drop_Down}
FOR ${Index} IN RANGE ${Length_Of_Lists_Items}
LOG ${Index} html=true
Click Element ${Xpath_Departure_DropDown}
sleep 2 seconds
run keyword and continue on failure Select From List By Index ${Xpath_Departure_DropDown_Options}[${Index}]
sleep 2 seconds
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
END
机器人框架关键字:
${Xpath_Departure_DropDown}= "xpath://*[starts-with(@class,'container')]//select[@name='fromPort']"
${Xpath_Departure_DropDown_Options}= "xpath://select[@name='fromPort']/option"
KW_14: Choose your departure city Drop Down:
@{All_Items_In_Drop_Down}= Get List Items ${Xpath_Departure_DropDown} values=True
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
${Length_Of_Lists_Items}= get length ${All_Items_In_Drop_Down}
FOR ${Index} IN RANGE ${Length_Of_Lists_Items}
LOG ${Index} html=true
Click Element ${Xpath_Departure_DropDown}
sleep 2 seconds
run keyword and continue on failure Select From List By Index ${Xpath_Departure_DropDown_Options}[${Index}]
sleep 2 seconds
${All_Items_In_Drop_Down_Label}= Get Selected List Label ${Xpath_Departure_DropDown}
${All_Items_In_Drop_Down_Value}= Get Selected List Value ${Xpath_Departure_DropDown}
List Selection Should Be ${Xpath_Departure_DropDown} ${All_Items_In_Drop_Down_Value}
END
我认为您使用的“按索引从列表中选择”是不正确的。请检查以下文件:
它接受定位器和索引。当你经过的时候
${Xpath_Departure_DropDown_Options}[${Index}]
这根本没有意义,因为Xpath\u离开\u下拉选项是定位器本身。试一试
Select From List By Index ${Xpath_Departure_DropDown_Options} ${Index}
它抛出的错误是什么?