Selenium如何检查元素多次正确加载并记录结果

时间:2014-02-11 16:57:12

标签: selenium frameworks

我正在尝试使用机器人框架测试一个带有selenium的网站,我在2页之间前后检查并检查第二个页面(每次都加载问题页面)并保持计算结果,我是使用以下代码

def check_contents_page_loads(self, passed, failed, attempts, counter):
    self.driver.get(self.mm + '/config/views')
    attempts = int(attempts)
    passed = int(passed)
    failed = int(failed)
    counter = int(counter)
    return_passed = str(passed)
    return_counter = str(counter)

try:
    while attempts > 0:
    attempts -= 1
    counter += 1
    self.driver.find_element_by_class_name("nav-config").click()
    time.sleep(5)
    self.driver.find_element_by_class_name("nav-content").click()
    time.sleep(10)
    test = self.driver.find_element_by_class_name("resource-navigator").is_displayed()
    print(test)
    if test == "True":
        passed += 1
    else:
        failed += 1

except Exception, ex:
    logging.exception('dasse %s , %s' % (ex, Exception))
    return False

return return_passed, return_counter

当页面存在时,这可以工作,但如果页面不是,我会收到以下错误消息

无法指定返回值:预期的类似列表的对象,反而得到了bool。

从机器人我发送以下值

${passed} Set Variable 0
${failed} Set Variable 0
${attempts} Set Variable 20
${counter} Set Variable 0
${return_passed} ${return_counter} Check Contents Page Loads ${passed} ${failed} ${attempts} ${counter}
Should be Equal ${return_passed} ${return_counter}

1 个答案:

答案 0 :(得分:0)

当抛出异常时,你会返回一个假的bool。你需要纠正它。