zoukankan      html  css  js  c++  java
  • 解决selenium参数化读取excel时为float类型的问题

    环境:firefox57;seelenium:3.8;geckdriver:1.9;python27/36

    方法1

    1.使用xlwt模块,创建编辑并保存文件为.xls(2003版本)或者.xlsx(2007版本),亲测都不影响使用

    2.使用xlrd模块,读取这个文件的数字为u"186232332"

    3.运行脚本success,虽然报了个 File "<string>", line 1.//*[@id='content'],内部直接报错但不影响运行

     # -*- coding: utf-8 -*-
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import Select
    from selenium.common.exceptions import NoSuchElementException
    from selenium.common.exceptions import NoAlertPresentException
    import unittest, time, re
    from tool_for_all.excel_type import open_excel,excel_table_byindex
    import xlrd

    class GreylistAdd(unittest.TestCase):

    def setUp(self):
    self.driver = webdriver.Firefox()
    self.driver.implicitly_wait(30)
    self.base_url = "https://www.katalon.com/"
    self.verificationErrors = []
    self.accept_next_alert = True

    def test_greylistadd_haveid(self):
    open_excel(file='C:\Users\renqiwei\Desktop\study\cintel\rqw.xls')

    #根据索引获取Excel表格中的数据 参数:file:Excel文件路径 colnameindex:表头列名所在行的所以 ,by_index:表的索引
    excel_table_byindex(file= 'C:\Users\renqiwei\Desktop\study\cintel\rqw.xls',colnameindex=0,by_index=0)
    listdata =excel_table_byindex("C:\Users\renqiwei\Desktop\study\cintel\rqw.xls" , 0)

    print((listdata))

    if (len(listdata) <= 0 ):
    # print(listdata,type(listdata))
    assert 0 , u"Excel数据异常"
    for i in range(0 ,len(listdata)):
    #print(type(eval(listdata)))
    driver = self.driver
    #打开url
    driver.get("http://192.168.2.87:8080/rg_web/loginforFZ.shtml;JSESSIONID=567bf70b-2ce3-4f54-a99d-1fc800fdb2ea")
    #driver.get()
    #清空用户名框并输入
    driver.find_element_by_id("login_name").send_keys("ct_operator")
    #输入密码
    driver.find_element_by_id("password").send_keys("123456")
    #点击登录
    driver.find_element_by_xpath("//div[@onclick='loginSubmit()']").click()
    #点击主叫灰名单录入
    time.sleep(2)
    driver.find_element_by_xpath("//div[@id='taskOrder']/div/div/i").click()
    # ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=0 | ]]
    #点击新添
    time.sleep(5)#ji加载当前页面
    driver.switch_to.frame(driver.find_element_by_xpath("//iframe"))
    driver.find_element_by_xpath("//button[@onclick='addGreyList()']").click()
    #输入新添手机号
    driver.find_element_by_xpath("(//input[@name='calling_number'])[2]").send_keys(listdata[i]["addgreynum"])
    #输入加灰原因c
    driver.find_element_by_name("remark").send_keys(listdata[i]['addreason'])
    #点击保存
    driver.find_element_by_link_text(u"保存").click()
    # ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]
    #点击关闭页面
    driver.switch_to.default_content()#退出frame标签
    driver.find_element_by_xpath("//div[@id='layui-layer1']/span/a[2]").click()
    #点击右上角用户按钮
    driver.find_element_by_xpath("//div[@onclick='togglePro()']").click()
    #点击退出
    driver.find_element_by_xpath("//li[@onclick='quit()']").click()

    def is_element_present(self, how, what):
    try: self.driver.find_element(by=how, value=what)
    except NoSuchElementException as e: return False
    return True

    def is_alert_present(self):
    try: self.driver.switch_to_alert()
    except NoAlertPresentException as e: return False
    return True

    def close_alert_and_get_its_text(self):
    try:
    alert = self.driver.switch_to_alert()
    alert_text = alert.text
    if self.accept_next_alert:
    alert.accept()
    else:
    alert.dismiss()
    return alert_text
    finally: self.accept_next_alert = True
    #关闭浏览器
    def tearDown(self):
    self.driver.quit()
    self.assertEqual([], self.verificationErrors)

    if __name__ == "__main__":
    unittest.main()

    运行成功,很开森

     如果还有更好的,希望博友留言分享
  • 相关阅读:
    Windows 7 Phone 文档数据库Rapid Repository正式发布
    Adobe展示HTML5动画制作IDE
    详解Android实现全屏正确方法
    qtform.com计划
    Adobe加速布局移动开发:Flash Builder+Flex+AIR+Catalyst
    预览:Visual Basic与C#中的异步语法
    Windows 7主题中的壁纸从哪里来?
    F#的编译器及标准库使用Apache 2.0协议开源(暂时还没有看到未来)
    开发者谈Symbian、iPhone、Android、MeeGo平台
    MeeGo 1.1发布
  • 原文地址:https://www.cnblogs.com/RENQIWEI1995/p/8024527.html
Copyright © 2011-2022 走看看