51Testing软件测试论坛
标题:
python3.4.3 浏览器前进后退报错
[打印本页]
作者:
MMKK123
时间:
2016-4-24 17:29
标题:
python3.4.3 浏览器前进后退报错
#coding = utf-8
from selenium import webdriver
import time
browser = webdriver.Firefox()
#访问百度首页
first_url='http://www.baidu.com'
print ("now access %s") %(first_url)
browser.get(first_url)
#访问新闻页面
second_url ='http://news.baidu.com'
print ("now access %s")%(second_url)
#返回(后退)到百度首页
print ("back to %s ")%(first_url)
dirver.back()
#前进到新闻页
print ("forward to %s")%(second_url)
deiver.forward()
driver.quit()
now access %s
Traceback (most recent call last):
File "E:\BaiduYunDownload\功能测试\设置浏览器前进后退.py", line 11, in <module>
print ("now access %s") %(first_url)
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'
>>>
作者:
若尘_51
时间:
2016-4-25 08:35
你的脚本好几处错误啊: (至于你报的那个错误在我这里是没有的,我是python27 建议使用2.x版本的,兼容比较好)
#coding = utf-8
from selenium import webdriver
import time
browser = webdriver.Firefox()
#访问百度首页
first_url='http://www.baidu.com'
print ("now access %s") %(first_url)
browser.get(first_url)
#访问新闻页面
second_url ='http://news.baidu.com'
browser.get(second_url)
print ("now access %s")%(second_url)
#返回(后退)到百度首页
print ("back to %s ")%(first_url)
browser.back()
#前进到新闻页
print ("forward to %s")%(second_url)
browser.forward()
browser.quit()
作者:
若尘_51
时间:
2016-4-25 08:38
print ("now access %s") %(first_url) 是你写错了吧 3.0的python是需要将print里面的内容括起来的 print
(
("now access %s") %(first_url)
)
作者:
清晨一缕阳光
时间:
2016-4-25 08:51
这个报错信息,是你写的print方法报错,你检查下你写的print方法的type对不对
作者:
清晨一缕阳光
时间:
2016-4-25 08:58
定义变量没有写类型,first_url='http://www.baidu.com'。。。。。。frist_url 类型没有声明。
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2