FAQ

1.python+selenium+Safari浏览器,定位元素

selenium.common.exceptions.ElementNotVisibleException: Message: An element command could not be completed because the element is not visible on the page.

在GitHub上有人提出过同样的问题,https://github.com/SeleniumHQ/selenium/issues/5355,有一个回答如下:



可以参考https://bugs.webkit.org/show_bug.cgi?id=174710,这个bug在Safari开发版已经修复,但并未发布。

那么怎么解决Safari浏览器的点击问题呢?



解决方法如下:

通过调用js的方法进行操作

execute_script(script, *args)
#Example:
ele = browser.find_element_by_xpath('//*[@id="1$Menu"]/li')
browser.execute_script('arguments[0].click();', ele)

2.python3+selenium 3.13 + geckodriver 21.0,提示ConnectionResetError,切换为较低版本的driver即可

学习selenium时,如果sleep时间大于等于5秒,就会提示ConnectionResetError: [Errno 54] Connection reset by peer。

换成chrome浏览器,可以正常运行。

demo.py

from selenium import webdriver
from time import sleep, ctime
#chrome
#driver = webdriver.Chrome(executable_path='//Users/csj/Desktop/seleniumdriver/chromedriver/chromedriver')
#Firefoxdriver 21.0
driver = webdriver.Firefox(executable_path='//Users/csj/Desktop/seleniumdriver/firefoxdriver/21.0/geckodriver')
#Firefoxdriver 20.1
#driver = webdriver.Firefox(executable_path='//Users/csj/Desktop/seleniumdriver/firefoxdriver/20.1/geckodriver')
#Firefoxdriver 20.0
#driver = webdriver.Firefox(executable_path='//Users/csj/Desktop/seleniumdriver/firefoxdriver/20.0/geckodriver')
#Firefox 19.1
#driver = webdriver.Firefox(executable_path='//Users/csj/Desktop/seleniumdriver/firefoxdriver/19.1/geckodriver')
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
print(ctime())
sleep(5)
print(ctime())
driver.find_element_by_id("kw").send_keys("selenium")
driver.close()

使用Firefoxdriver 21.0,报如下错误:

Traceback (most recent call last):
File "/Users/csj/PycharmProjects/untitled/demo.py", line 13, in <module>
driver.find_element_by_id("kw").send_keys("selenium")
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 353, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 957, in find_element
'value': value})['value']
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
response = self.command_executor.execute(driver_command, params)
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute
return self._request(command_info[0], url, body=data)
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 496, in _request
resp = self._conn.getresponse()
File "/Users/csj/anaconda/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/Users/csj/anaconda/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/Users/csj/anaconda/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/Users/csj/anaconda/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

换成chrome,可以正常运行。老板提醒可能是版本的问题,分别用 Firefox 20.1, 20.0, 19.1,均能运行成功,没有再提示ConnectionResetError。

休眠时间设置为10秒,也没有再报错。

python selenium 问题汇总的更多相关文章

  1. WEB自动化(Python+selenium)的API

    在做Web自动化过程中,汇总了Python+selenium的API相关方法,给公司里的同事做了第二次培训,分享给大家                                         ...

  2. Python Selenium 文件上传之SendKeys

    昨天写了Web 文件下载的ui自动化,下载之后,今天就要写web 文件上传的功能了. 当然从折腾了俩小时才上传成功.下面写一下自己操作的步骤 首先网上说的有很多方法 如 input 标签的最好做了,直 ...

  3. Python selenium的js扩展实现

    python写的数据采集,对一般有规律的页面用 urllib2 + BeautifulSoup + 正则就可以搞定. 但是有些页面的内容是通过js生成,或者通过js跳转的,甚至js中还加入几道混淆机制 ...

  4. 【Python + Selenium】之JS定位总结

    感谢:小琰子 Python+Selenium 脚本中的一些js的用法汇总: 1.滚动条 driver.set_window_size(500,500) js = "window.scroll ...

  5. python+selenium 简单尝试

    前言 selenium是一种自动化测试工具,简单来说浏览器会根据写好的测试脚本自动做一些操作. 关于自动化测试,一开始接触的是splinter,但是安装的时候发现它是基于selenium的,于是打算直 ...

  6. python+selenium 浏览器的问题

    以前用selenium调用firefox是不需要驱动的,最近安装了python3.52+最新的firefox 发现调不起来了 搜索以后发现Firefox 47+需要搞个firefox的驱动 gecko ...

  7. 一次完整的自动化登录测试-基于python+selenium进行cnblog的自动化登录测试

    Web登录测试是很常见的测试!手动测试大家再熟悉不过了,那如何进行自动化登录测试呢!本文作者就用python+selenium结合unittest单元测试框架来进行一次简单但比较完整的cnblog自动 ...

  8. Python + Selenium 实现登录Office 365

    最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...

  9. python+selenium+Robot

    准备工作: 1.下载python2.7 http://python.org/getit/ 2.下载下载setuptools [python 的基础包工具] 可以帮助我们轻松的下载,构建,安装,升级,卸 ...

随机推荐

  1. logback转义符与MDC

    关于MDC的使用,可以结合filter一块使用,将需要串联的上下文的关键信息,通过header进行传递,然后通过配置%X{userId}将信息打印出来. MDC.put("userId&qu ...

  2. C# winform 编程 向ACCESS数据库导入EXCEL表使用心得

    public string MyConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ErLake.mdb&quo ...

  3. 高强度减脂Tabata练习

    每个动作20秒 动作间休息10秒 8个动作为一组 每次做四组 让你大汗淋漓全身酸爽 波比跳 ▼ 跳起箭步蹲 ▼ 登山者 ▼ 俯卧撑 ▼ 卷腹 ▼ 开合跳 ▼ 高抬腿 ▼ 俄罗斯转体 ▼ Bingo ▼ ...

  4. [Scala]Scala学习笔记七 正则表达式

    1. Regex对象 我们可以使用scala.util.matching.Regex类使用正则表达式.要构造一个Regex对象,使用String类的r方法即可: val numPattern = &q ...

  5. 50个必备常用的jQuery代码段

    1. 如何修改jQuery默认编码(例如默认UTF-8改成改GB2312): $.ajaxSetup({ ajaxSettings:{ contentType:"application/x- ...

  6. 玩转TypeScript(3)--数组

    数组的语法和语义与C#数组非常相似,首先要指定一个数组名,后跟冒号,冒号后面紧跟数组的类型,数组类型名后面跟方括号表示当前定义的是一个数组,对于一个空的数组定义,可以使用如下的语法: btnArray ...

  7. https页面证书验证、加密过程简介

    1.服务器向CA机构获取证书(假设这个证书伪造不了),当浏览器首次请求服务器的时候,服务器返回证书给浏览器.(证书包含:公钥+申请者与颁发者的相关信息+签名) 2.浏览器得到证书后,开始验证证书的相关 ...

  8. C++基础之 成员变量初 始化赋值

    摘要: C++成员变量 初始化赋值 你都清楚吗?还有好多坑,好多细节也不知道... 今天在写一个类的时候,由于该类的一个成员变量是引用,所以初始化出现了问题,查了一下之后,才发现,原来引用的初始化和c ...

  9. SIM800C 透传模式

    /******************************************************************************* * SIM800C 透传模式 * 说明 ...

  10. [LeetCode&Python] Problem 589. N-ary Tree Preorder Traversal

    Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary  ...