zoukankan      html  css  js  c++  java
  • python运行selenium时出现的一个错误总结

    1.SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

    场景:运用pandas修改某个序号所对应的key值时出现了该类警告

    https://stackoverflow.com/questions/26724378/pandas-settingwithcopywarning

    代码:

    df_index = df.loc[index]
    df_index[key] = value

    修改:

    df.loc[index,key] = value

    这里的“index”是df数据中序号,“key”是标签所对应的key,“value”为需要修改的内容,value可以为int、str、以及类对象

    2.selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (456, -17)

    场景:打开微信公众号的链接之后,将浏览器修改为手机模式之后,通过click去点击的时候提示不可点击
    办法:设置浏览器为最大化之后就可点击了

    3.selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified

    原因:定位方式写错了

    4.SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape

    场景:在“ini”为后缀名的文件中写入的文件路径

    方法:输入路径或者网址时用的是反斜杠‘’导致错误,如果用双正斜杠就好了'//'

     5.TypeError: invalid type comparison

    场景:使用operator对两个list进行比价时,出现问题

    原因:有一个list是str类型的数据,有一个数int类型的数据

    方法:将某一个list里面的数据进行转换之后在添加到list中然后在进行比较

    6.TypeError: 'module' object is not callable

    from导入的时候包名写错

    场景:手动导入包时,因大小写的关系或者包名重新修改了,导致找不到相应的包

     7.TypeError: not all arguments converted during string formatting

    print进行输入时语句上只写了两个%s,但是参数却有多个。

    场景:进行输出时,输出参数多于了定义的参数

    8.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

    页面刷新之后需要重新定位。

    场景:执行某一个动作之后,界面重新刷新。此时元素需要重新定义

    9.ValueError: Can only compare identically-labeled DataFrame objects

    错误原因:需要比较的两个数据类型(即type类型不一致)不一致

    出项的场景:

    1.两个pandas对象进行比较时,各自长度不相等出现的错误
    2.同一个key下面的数据 value 数据 type 不同

    10.TypeError: argument of type 'NoneType' is not iterable

    错误原因:程序运行过快,没有设置中间变量时导致

    出现场景:想获取df里面的某个值并传入相应的函数中

    weizhi = self.overall[dn.dailyCity()]
    dl.setSelectorText(weizhi)

    11.ValueError: invalid literal for int() with base 10: '2018-04-05 00:00:00-2018-05-06 23:59:59'

    错误原因:自己写的时间戳转日期的函数时,本应传入时间戳,而我传入的是日期格式所以导致这个问题

    12.TypeError: expected string or bytes-like object

    错误原因:拿一个空的数据去执行正则比较。

    场景:

    my_sql = None,然后运行regular = re.match('^SELECT', my_sql)

    13.TypeError: not all arguments converted during string formatting

    错误原因:数据打印的格式输入有误

    出现场景:log日志进行输出时导致
    self.log.info( inspect.stack()[0][3] % "%s 公告页面的tbody不存在" )

    修改后:self.log.info(  "%s 公告页面的tbody不存在" % inspect.stack()[0][3] )

    14.tuple index out of range

    错误原因:好像是因为mysql语句指令太长导致,当时同时有多个错误。后面没有进行校验

    15.bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

    错误原因:没有安装lxml,然后bs4获取数据之后又使用lxxml进行数据解析然后错误错误

    解决方案:pip install lxml就解决了

    16.TypeError: not all arguments converted during string formatting

    错误原因:time.localtime(status_time)转换的数据之后不能通过字符串形式进行输出

    场景:pring("时间" + time.localtime(status_time))

    17.TypeError: Object of type 'WebElement' is not JSON serializable

    错误原因:driver通过css_selector来获取元素时,应该传入css_selector路径而我传入一个int数据

     

    18.local variable 'attribute' referenced before assignment

    错误原因:局部变量元素attribute没有函数

    场景:EC判断一个元素是否找到,如果找到就获取attribute属性值,没有知道就返回FALSE。

    而当时没有找到我也去获取attribute属性值然后就报错了,都是复制粘贴的错误

    19.yaml.scanner.ScannerError: while scanning a block scalar expected a comment or a line break, but found 't'

    错误原因: 在编写元素路径时(thead: > tbody > tr) 多写了一个冒号,然后报错

    20.ValueError: Unsupported or invalid CSS selector: ">tbody"

    错误原因:使用bs4爬取数据时,因通过select来查找数据,多写了>tbody。提示找不到tbody。去掉该tbody即可

    21.AttributeError: 'NoneType' object has no attribute 'encoding'

    错误原因:mysql进行链接时,字符集charset没有设置为utf8而是设置为QQAA导致的。
    场景:链接数据库时charset设置有误

    self.connect = pymysql.Connect(
    host=host,
    port=port,
    user=user,
    passwd=passwd,
    db=db,
    charset=charset
    )

    22.ValueError: I/O operation on closed file.

    错误原因:使用with open()as file时,在with里面创建参数然后在with外面进行使用

    针对with写入数据一个优化:with open() as file:往csv写入数据时,每个数据之间都有一个空格。
    解决方法: open(newline='')中指定newline参数为空,官方解释该参数是每个csv之间的分割符

    23.http.client.CannotSendRequest: Request-sent

    错误原因:在接口请求数据时网络请求太快

    解决方法:每个请求之间加个休眠的时间

    24.TypeError: 'NoneType' object is not iterable
    错误i原因:yaml数据为空时,去读取yaml文件数据
    解决方法:在yaml里面随意写入一些数据信息

    25.KeyError: <module 'project_path' from 'E:\project_path\__init__.py'>

    报错的地方: HTMLTestRunner执行多任务的ceses时,出现这类问题。单个cese执行的时候并没有报错
    错误原因: case包命名不规范
    方法: 对case的包名进行修改

    26.KeyError: 'pass_ticket'

    错误原因:wxpy框架登陆微信时出现这个错误
    解决方案:不要使用小号微信或者有异常又或者没有使用web登录过的微信号

    27.HTMLTestRunner:生成的报告中,“通过”按钮无法点击。

    原因:运行case时没有输出语句

    解决方案:每个case都加个log

    28.最开始unittest中defaultTestLoader的discover函数中top_level_dir属性传入none

    多线程运行的时候出现了匪夷所思的错误,发现top_level_dir需要传入项目的起始路径

    discover = unittest.defaultTestLoader.discover(case_path,
    pattern=rule,
    top_level_dir=CUR_PATH)

    对该字段还没有理解,希望有人给出更好的解释

    日后再更新。。。。。。。。

  • 相关阅读:
    jstree 的使用(增 删 改 查)
    关于Random 和 List<int>的Exist的方法使用
    编译器错误消息: CS0016: 未能写入输出文件“c:WindowsMicrosoft.NETFramework64v4.0.30319Temporary ASP.NET Files oot1b124ac2fb984fcApp_global.asax.vbtifrrw.dll”--“拒绝访问。 ”
    SQL Server执行动态SQL正确方式
    C#设计模式——简单说(简单工厂模式)
    c#设计模式——简单说(建造者模式)
    nginx将http请求转发到https
    maven出现:Failed to execute goal on project ...: Could not resolve dependencies for project ...
    动态切换element-ui表格中每行的icon
    axios拦截token过期,返回401的情况
  • 原文地址:https://www.cnblogs.com/xiaodingdong/p/8391078.html
Copyright © 2011-2022 走看看