selenium2自动化测试实战学习路线

这个文章针对家里电脑遇到的问题及解决办法

遇到的问题有这几个:

1,py文件启动Firefox时报错,问题根源,没有安装火狐驱动,回头安装(网盘已上传geckodriver)

2,py文件调用狐火浏览器,报错:

selenium2自动化测试实战学习路线_第1张图片
1

还有这个错:plugin container for firefox 已停止工作     2

搜到解决方法:1)移除:C:\Windows\SysWOW64\Macromed\Flash\NPSWF32_15_0_0_152.dll

2)参考这个方法,从安装插件入手http://www.cnblogs.com/lipijin/p/4016530.html,删除插件,我在我的安装里面没有看到这个插件

暂时是按照1)进行,上面的图片”已停止工作"提示还是有,就先不管了。



3,执行这个文件

selenium2自动化测试实战学习路线_第2张图片
报这个错


selenium2自动化测试实战学习路线_第3张图片

selenium.common.exceptions.WebDriverException: Message: Expected [object Undefined] undefined to be a string

搜索解决方法:更换最新的geckodriver,同时将解压后的路径添加到path里面。

发现还是报这个错。-----解决方法:将驱动放到python的安装路径下,path内不需要添加。再执行,已经不报这个错了。。报别的了。容我继续。

4,再次执行py文件

selenium2自动化测试实战学习路线_第4张图片
再这一句执行时已经报错:driver = webdriver.Firefox()

5,家里的电脑的问题:selenium.common.exceptions.WebDriverException: Message: Can't load the profile.Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.

不能加载profile。。这是什么鬼。。

实在没有办法的办法:卸载selnium2.48.0,安装selenium3.34  不行。重新安装回2.48.0,卸载最新版的火狐浏览器,这期间我也试着下载ie浏览器驱动,没有找到地儿。安装火狐40版本(低版本),再运行py文件,调用火狐浏览器,不再报profile的问题。

D:\Python\pypy>python3 youdao432.pyTraceback (most recent call last):  File "youdao432.py", line 6, indriver.find_element_by_id("query").send_keys('hello')

File "D:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver

.py", line 234, in find_element_by_id

return self.find_element(by=By.ID, value=id_)

File "D:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver

.py", line 712, in find_element

{'using': by, 'value': value})['value']

File "D:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver

.py", line 201, in execute

self.error_handler.check_response(response)

File "D:\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhand

ler.py", line 181, in check_response

raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate ele

ment: {"method":"id","selector":"query"}

Stacktrace:

at FirefoxDriver.prototype.findElementInternal_ (file:///C:/Users/ADMINI~1/A

ppData/Local/Temp/tmpptv94v7t/extensions/[email protected]/components/driv

er-component.js:10659)

at FirefoxDriver.prototype.findElement (file:///C:/Users/ADMINI~1/AppData/Lo

cal/Temp/tmpptv94v7t/extensions/[email protected]/components/driver-compon

ent.js:10668)

at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/ADMINI~1/Ap

pData/Local/Temp/tmpptv94v7t/extensions/[email protected]/components/comma

nd-processor.js:12534)

at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/ADMINI~1/AppD

ata/Local/Temp/tmpptv94v7t/extensions/[email protected]/components/command

-processor.js:12539)

at DelayedCommand.prototype.execute/< (file:///C:/Users/ADMINI~1/AppData/Loc

al/Temp/tmpptv94v7t/extensions/[email protected]/components/command-proces

sor.js:12481)

-----0816继续

这次同样是这个py文件,这次写时,我看了文本框的id,是translateContent,而不是query。再次运行成功。这个问题算是个问题吗?我是照着书本敲的。看来不能读死书。。。现在再看上面的那一堆报错信息,额,以后再看吧。

selenium2自动化测试实战学习路线_第5张图片

5,selenium工具打开的火狐与本地快捷方式打开的火狐不一样(本地的有收藏网址)

webdriver在启动浏览器时,启动的一个干净的没有任务、插件及cookies信息的浏览器(即使你本机的firefox安装了某些插件,webdriver启动firefox也是没有这些插件的)


6,driver.find_element_by_id("TANGRAM__PSP_8__submit").click()

#到上面这句时报错了。找不到id,找不到class_name

隔天,再重新利用firebug查找元素id,发现不再报错了。早上看时,id 是7 不是 8。。

昨晚也被这个问题困住了,不知道哪里出了问题。见login431.py

7,执行 driver.quit() 报错

selenium2自动化测试实战学习路线_第6张图片

Plugin Container for Firefox 已停止工作

http://blog.csdn.net/luna33/article/details/49100413

按照这里连接里修改,依然会出现这个图,因为selenium调用的火狐与我本身设置的火狐浏览器是两回事。同上面 5。

8,运行完py文件报错:for checkbox in checkboxes:

TypeError: 'WebElement' object is not iterable

检查,是checkboxes= driver.find_element_by_xpath("//input[@type='checkbox']")

这里的问题,方法中element应该是elements

9,driver.find

你可能感兴趣的:(selenium2自动化测试实战学习路线)