我需要迭代组合框中的项目,它不是创建为常规组合框(选择元素),但它是一些“复杂”的JS组件。 我在python中编写了一个while循环来按下按键(以获得另一个项目),检查页面上是否有一些消息,如果消息不在那里,循环应该结束。但它不能正常工作。它不会通过1项,但它似乎走了3项。 (我打印出“真正的/错误的消息”,所以我可以看到,如果它选择了第15项,则只有5条消息来自循环而不是15条) 我不知道如何强制按下按键以缩短时间,只移动一个项目。机器人框架,硒,Python键在循环中的组合框跳过值
功能:
def find_not_used_protocol(self,entity):
actionChain = self.get_action_chain()
message = True
msgs=[]
while message:
#actionChain.key_down(Keys.ARROW_DOWN) #I tried this but it did not behave better
actionChain.send_keys(Keys.DOWN).perform()
actionChain.release()
#BuiltIn().sleep(1) #I tried this but it did not behave better
message = self.get_library_instance()._is_text_present(
"This protocol already has a "+entity+". Please select different protocol.")
msgs.append(message) #this is here just for better debug
return msgs
使用机器人:
Set Protocol for ${entity}
Wait Until Element Is Visible ${PROTOCOL INPUT} 20
Input Text ${PROTOCOL INPUT} 0001
click element ${PROTOCOL ARROW DOWN}
#set selenium speed .5 seconds #It does not really help
${msgs}= find not used protocol ${entity}
log to console ${msgs}
这是组合,它可能有400个项目等。对于他们中的一些有页面上显示的消息,对于一些不是。我需要停止在没有消息,该项目的环...
代码get_library_instance的(我的功能):
def get_library_instance(self):
if self.library is None:
self.library = BuiltIn().get_library_instance('ExtendedSelenium2Library')
return self.library
代码_is_text_present(从Selenium2Library)的:
def _is_text_present(self, text):
locator = "xpath=//*[contains(., %s)]" % utils.escape_xpath_value(text);
return self._is_element_present(locator)
我会很高兴任何建议如何使其工作。谢谢!
循环将在最坏的情况下运行15次,否则只要'message'为'false',它就会出来。你想达到什么目的? –
我需要检查消息是否出现在页面上的第一个组合框中的每个项目。当第一个项目没有找到消息时结束循环。但是目前它停止在组合框第15项,但实际上,第6和第7项没有消息,所以循环应该在这里结束。甚至在组合框中有更多400个项目的情况下,即使有很多没有消息的项目,它也会继续迭代。 – neliCZka
分享'get_library_instance'和'_is_text_present'的代码 –