Selenium-异常:Element is not currently visible and so may not be interacted with的解决
来源:互联网 发布:天河工商局软件地址 编辑:程序博客网 时间:2024/05/18 00:57
Selenium-异常:Element is not currently visible and so may not be interacted with的解决
二、
我们需要本地上传文件时,一般找个那个input元素,然后send_keys把本地的文件路径传进去就好了。像这样:
driver.find_element_by_name("files").send_keys("D:\\manual.pdf")
但是最近遇到一个问题,上传的时候报错啦。报错信息如下:
selenium.common.exceptions.ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:
它这说的visible和css里元素的visibility属性好像还不是一个东西,就算用js改变这个元素的CSS属性为可见的还是会报上面这个错误。后来看到webElement类里有个方法叫is_displayed()解释是"Whether the element would be visible to a user" 所以这里说的可不可见是对用户来说的,之所以会报不可见的错是因为本地上传里的input是经过美化的,已经看不到了,所以需要用js改变这个元素的样式把本来面目显示出来~~~ 这就需要自己调样式了。Js里有个attr方式可以用来改变元素的样式,示例如下:
driver.execute_script("$('.fileinput-button input').eq(0).attr('style','height:20px;opacity:1;display:block;position:static;transform:translate(0px, 0px) scale(1)')")
改了样式后,找到该元素调用了一下is_displayed(),返回值是true了,再运行脚本就不会报错,文件顺利上传上去了~~
原来的上传按钮:
被还原出来的input 如下:
总结:遇到被美化的元素,导致出现元素不可见的异常时,就用JS把它的样式还原回去~
- Selenium-异常:Element is not currently visible and so may not be interacted with的解决
- Selenium-异常:Element is not currently visible and so may not be interacted with的解决
- selenium webDriver: Element is not currently visible and so may not be interacted with
- Webdriver Element is not currently visible and so may not be interactedwith 解决方法
- Element is not currently visible and so may not be interactedwith 解决方法
- WebDriver遇到Element is not currently visible and so ...解决
- selenium:Element is not visible
- Webdriver Element is not currently visible 解决方法
- selenium +Python 测试时报 “Element is not visible”解决方法
- java Selenium 发送126邮件 解决element not visible
- org.openqa.selenium.ElementNotVisibleException: element not visible
- selenium错误"element not visible"问题
- element not visible的解决方法
- rails and gem is currently not installed (解决)
- 解决selenium报错Element is not clickable at point...
- zabbix监控报错zabbix server is not running: the information displayed may not be current的解决
- python selenium to click an element not visible
- Error:JAVA_HOME is not set and could not be found 解决般的法
- redis---RDB
- 数据结构练习——简单双链表
- iOS
- contos7.4 安装lump环境php7.2+mysql7.2+nginx(最全面,无误的)
- Android 设置全屏沉浸式透明状态栏的工具类(超级简单,两步实现)
- Selenium-异常:Element is not currently visible and so may not be interacted with的解决
- adb和adbd分析
- syslog架构
- idea多模块开发
- Mac OS 安装 与 卸载 JDK
- Email 控件Aspose.Email 12月新版17.12发布 | 附下载
- 项目服务端的创建(丛林战争项目)
- Oracle中查询前10条记录
- HttpCLient请求困扰了两天的问题