这两天要在阿里云日志中操作UI,以输入关键字搜索日志。

在send_keys时报错element not interactable。

iframe

第一个问题是iframe,通过切换iframe解决:

driver.switch_to.frame(0)  # 索引从0开始

span

第二个问题是span。

F12查看html长这样:

①find_element(pre).click 有效,说明iframe切换成功了

②find_element(span2).send_keys报错

element not interactable

span不支持send_keys。

第一个方法,通过调js来解决,设置span的innerText

search_text = 'error'
log_search_span = driver.find_element_by_xpath(
'//*[@id="queryEl"]/div[2]/div/div[6]/div[1]/div/div/div/div[5]/div/pre')
js = 'arguments[0].innerText=arguments[1];'
driver.execute_script(js, log_search_span, search_text)

第二个方法,添加属性contenteditable

search_text = 'error'
log_search_span = driver.find_element_by_xpath(
'//*[@id="queryEl"]/div[2]/div/div[6]/div[1]/div/div/div/div[5]/div/pre')
js = 'arguments[0].setAttribute("contenteditable", "true");'
driver.execute_script(js, log_search_span)
log_search_span.send_keys(search_text) # 可编辑后send_keys成功

不简单

虽然值设置成功了,但是不能用,在查询时,还是用空值在查询。

经过分析,得出以下线索:

  1. 设置的元素值是已经生成后的dom
  2. 程序真正的dom隐藏在js/后端中
  3. span是由js或后端动态生成的
  4. 要想模拟出来,需要分析js实现代码
  5. 控制台的js代码是加密混淆过的
  6. selenium的send_keys已经是模拟键盘输入了,不知道为啥没有触发相关代码,存值到dom

网上很多的方案是<input>标签,比较好解决,阿里的这个span还真有点不简单。

chrome console调试js

最后分享一下chrome console调试js的方法。

F12后,在元素上右键,选择Copy selector,复制selector

切换到console,输入即可定位到该元素:

document.querySelector('#queryEl > div.react-codemirror2 > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre > span > span').innerText;

send_keys报错element not interactable的更多相关文章

  1. selenium报错Element is not clickable at point及四种解决方法

    使用Selenium时,触发点击事件,经常报如下异常:Element is not clickable at point 1.未加载没加载出来就等待元素加载出来,再往下执行.可以使用python库ti ...

  2. 使用饿了么ui表单验证报错: [Element Warn][Form]model is required for validat

    [Element Warn][Form]model is required for validat 如文末的完整例子: 该提示说的是 form表单需要一个绑定一个 对象(使用:model=" ...

  3. ReactJs 报错 Element type is invalid: expected a string (from built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Me`.

    今天在重构一个页面的时候,碰到了一个error,具体的error信息如下图中所示: 最后经过一番查找定位,终于找到了问题所在,原因就是在父组件引用子组件时多加了一个大括号. import {Chart ...

  4. appium报错Message: Cannot set the element to ‘XXXX’. Did you interact with the correct element?

    appium+python+android 在定位到模块输入内容的时候遇到了一个问题 send_keys报错 appium报错Message: Cannot set the element to 'X ...

  5. 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

    解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...

  6. web.xml文件报错:cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'.

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  7. select2取值报错,Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('hidden') does not support selection.

    用到了 select2 组件来多选收件人,用搜狗浏览器(6.2版高速模式)在执行到如下这句时报错(Uncaught InvalidStateError: Failed to read the 'sel ...

  8. 关于xpath语句完全正确,但是页面报错: no such element: Unable to locate element: {"method":"xpath","selector":"xpath"}

    之前使用selenium-webdriver来写UI的自动化脚本,发现有一个元素一直无法定位,查看其源码,如下 利用xpathChecker验证了xpath语句的是正确的,但是控制台一直报错: no ...

  9. jQuery配合html2canvas 使用时 报错 Uncaught (in promise) Provided element is not within a Document

    报错代码: 这个函数运行时 function download(){ var element = $("#demo"); //jquery 获取元素 //这里将会报错 html2c ...

随机推荐

  1. 对GridFS数据进行分片

    On this page files 集合 chunks 集合 在对 GridFS 存储进行分片时,需要注意以下的情况: files 集合 大多数情况下不需要对 files 集合进行分片,这个集合通常 ...

  2. git设置忽略文件.gitignore

    在仓库目录下新建一个名为.gitignore的文件(因为是点开头,没有文件名,没办法直接在windows目录下直接创建,必须通过右键Git Bash,按照linux的方式来新建.gitignore文件 ...

  3. 网络命令-nc(二)

    继续Netcat 这个命令吧 1:远程拷贝文件 在本地输出 文件debian.img 到 192.168.5.40 主机12345端口监听 nc -v 192.168.5.40 12345 < ...

  4. Linux查看软件安装路径,和文件的位置

    查看软件是否安装:rpm -qa|grep xx 列出软件安装包安装的文件:rpm -ql 直接使用rpm -qal |grep mysql 查看mysql所有安装包的文件存储位置 通过find去查找 ...

  5. 二维码相关---java生成二维码名片,而且自己主动保存到手机通讯录中...

    版权声明:本文为博主原创文章,未经博主credreamer 同意不得转载 违者追究法律责任. https://blog.csdn.net/lidew521/article/details/244418 ...

  6. Java技术中的三大特性

    1.虚拟机                                Java虚拟机JVM(Java Virtual Machine)在Java编程里面具有非常重要的地位,约相当于前面学到的Jav ...

  7. NOIP后一波总结

    我的山寨较为可靠分数为305(洛谷是真的水~显然不能用啊,果断换了一组合适的数据) 据大神们估计,得奖的分数在280, 我肯定是没有啥希望了.(我旁边的lxy同学从初二开始,每次以超分数线至少60分的 ...

  8. ubuntu16.04安装docker11.09

    1.    安装Docker 操作系统 ubuntu16.04 1.1.   配置源文件 $sudo apt-get update #允许 apt 命令 HTTPS 访问 Docker 源 $sudo ...

  9. test命令-linux shell 脚本

    #!/bin/bash # This is program will check you file name,which sys has or not,end print types. #2019/0 ...

  10. 你了解SEO中的时效性吗?

    你了解SEO中的时效性吗? 本文摘自web前端早读课,侵删. 前言 最近刚好在负责一个新项目,App在还没上线的前提上,PC/WAP可以优先部署相关SEO,这样在后续的推广中得以运用.今日早读文章由腾 ...