上周碰到了 Unable to locate element,即“无法定位元素”,后靠两行代码解决:

wait = ui.WebDriverWait(driver,5)
wait.until(lambda driver: driver.find_element_by_id("username"))

今天又碰到 cannot focus element,即“无法聚焦元素”,开始以为是 xpath 问题,换了种定位方法,还是无法聚焦。把这段代码单独存放到一个文件里,执行该文件:

......

driver.get("http://xxx")

driver.find_element_by_xpath("//input[@placeholder='搜索']").clear()
driver.find_element_by_xpath("//input[@placeholder='搜索']").send_keys("xxxxx")

......

执行成功,可见定位本身没有问题,莫非跟 Unable to locate element 一样,

于是又加入智能等待 WebDriverWait,即如下两行代码:

wait = ui.WebDriverWait(driver,5)
wait.until(lambda driver: driver.find_element_by_id("username"))

问题解决(超时时间5秒可根据实际情况而定)。

不能聚焦元素问题 WebDriverException: Message: unknown error: cannot focus element的更多相关文章

  1. python selenium 报错unknown error: cannot focus element 解决办法

    登录框由于js限制,定位到元素后无法sendkey ,sendky报错如下: selenium.common.exceptions.WebDriverException: Message: unkno ...

  2. selenium.common.exceptions.WebDriverException: Message: unknown Error: cannot find Chrome binary

    使用Chrome浏览器时,经常会遇到以下报错:浏览器没有调用起来 selenium.common.exceptions.WebDriverException: Message: unknown Err ...

  3. Python3 Selenium自动化测试赋值出现:WebDriverException: Message: unknown error: call function result missing 'value'

    Python3 Selenium自动化测试赋值出现:WebDriverException: Message: unknown error: call function result missing ' ...

  4. selenium WebDriverException: Message: unknown error: DevToolsActivePort file doesnt exist

    在centos中使用无头chrome报以下错误 selenium.common.exceptions.WebDriverException: Message: unknown error: DevTo ...

  5. WebDriverException: Message: unknown error: Chrome failed to start: crashed

    the last answer WebDriverException: Message: unknown error: Chrome failed to start: crashed

  6. robotframework执行用例时,报错selenium.common.exceptions.WebDriverException: Message: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinl

    在用robotframework编写移动端测试用例(用chrome浏览器模拟手机浏览器),执行用例时, 报错selenium.common.exceptions.WebDriverException: ...

  7. 输入操作遇到unknown error: cannot focus element

    事件背景:写脚本遇到sendkey时报错unknown error: cannot focus element,仔细查了,元素定位什么的都没问题,通过js注入修改数据后,保存成功,但是再进入编辑状态查 ...

  8. RF运行脚本报错:WebDriverException: Message: unknown error: call function result missing

    原因:浏览器驱动与浏览器版本不对应

  9. 关于执行webdriver.Chrome; 报错WebDriverException: Message: unknown error: Element is not clickable at point (1085, 103)

    from selenium import webdriverfrom time import sleep dr = webdriver.Chrome() dr.get("http://pj1 ...

随机推荐

  1. 【H5最强攻略】百度人脸情绪实时识别

    最近看的各位大佬都在体验百度大脑2019年全新上线的24项AI能力! (我也按耐不住了,赶紧走一波- 哈哈) 接下来要介绍的就是H5端的人脸检测攻略. 附带详细的介绍,代码,以及演示体验等 欢迎提出各 ...

  2. 关于discuz的fap.php 漏洞问题

    discuz后台SQL注入漏洞 discuz的/faq.php的$action == 'grouppermission'处理逻辑中,对$gids未进行初始化,黑客可通过构造特殊HTTP请求借助变量覆盖 ...

  3. 使用bean接收ajax表单提交数据包含文件上传

    这几天写带图片上传的表单提交,一个配置小程序活动弹出框样式的功能,记录一下一些需要注意的地方 首先是 前端 JSP 文件的表单 <form class="search-wrapper& ...

  4. 示例:Oracle表锁、行锁模拟和处理

    for update模拟锁表 --session 1 SQL> select * from tt for update; --session 2 SQL> update tt set id ...

  5. 网络管理和nmcli命令的使用——网络接口配置-bonding实验步骤

    (实验)网络接口配置-bonding  Bonding 将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡.直接给两块网卡设置同\一IP地址是不可以的.通过bonding,虚拟一块网 ...

  6. Java使用JDBC连接SQL Server数据库|实现学生成绩信息系统

    Java实验四 JDBC 使用SQL Server数据库或者MySQL数据库各自的客户端工具,完成如下任务: (1)创建数据库students: (2)在数据students中创建表scores,包括 ...

  7. asp.net的原理

    Asp.net的作业流是指什么?很多人都不是很了解,也不知道是用来干什么的有怎样运用,其实能够从简略的基础了解. 作业流(Workflow),便是“事务进程的部分或全体在核算机使用环境下的主动化”(i ...

  8. [LeetCode] 42. Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  9. CSharpGL(54)用基于图像的光照(IBL)来计算PBR的Specular部分

    CSharpGL(54)用基于图像的光照(IBL)来计算PBR的Specular部分 接下来本系列将通过翻译(https://learnopengl.com)这个网站上关于PBR的内容来学习PBR(P ...

  10. python--各种锁机制归纳整理

    Q:为什么要用锁?什么样的业务场景下需要用锁? 就拿之前的工单系统来说,当审批方式为角色组审批时,代表该角色组内任意一人审批即可,这时,该角色组内成员的系统上都是可以显示审批按钮,如果此时A审批员和B ...