= array(); } $post['classname'] = 'post'; } function comment_format(&$post) { global $conf, $uid, $gid, $forumlist; if (empty($post)) return; $forum = $post['fid'] ? forum_read($post['fid']) : ''; $thread = well_thread_read_cache($post['tid']); if ($thread) { //$post['fid'] = $thread['fid']; $post['closed'] = $thread['closed']; $post['subject'] = $thread['subject']; $post['url'] = $thread['url']; } else { $post['closed'] = 0; $post['subject'] = lang('thread_not_exists'); $post['url'] = ''; } $post['create_date_fmt'] = humandate($post['create_date']); //$post['message'] = stripslashes(htmlspecialchars_decode($post['message'])); $user = user_read_cache($post['uid']); $post['username'] = array_value($user, 'username'); $post['user_avatar_url'] = array_value($user, 'avatar_url'); $post['user'] = $user ? user_safe_info($user) : user_guest(); isset($post['floor']) || $post['floor'] = 0; // 权限判断 $post['allowupdate'] = 2 == array_value($forum, 'comment', 0) && ($uid == $post['uid'] || forum_access_mod($post['fid'], $gid, 'allowupdate')); $post['allowdelete'] = group_access($gid, 'allowuserdelete') && $uid == $post['uid'] || forum_access_mod($post['fid'], $gid, 'allowdelete'); $post['user_url'] = url('user-' . $post['uid'] . ($post['uid'] ? '' : '-' . $post['pid'])); if ($post['files'] > 0) { list($attachlist, $imagelist, $filelist) = well_attach_find_by_pid($post['pid']); // 使用图床 评论使用图床,mysql会过多,写死链接到内容是减轻mysql的过多的方法 if (2 == $conf['attach_on']) { foreach ($imagelist as $key => $attach) { $url = $conf['upload_url'] . 'website_attach/' . $attach['filename']; // 替换成图床 $post['message'] = FALSE !== strpos($post['message'], $url) && $attach['image_url'] ? str_replace($url, $attach['image_url'], $post['message']) : $post['message']; } } $post['filelist'] = $filelist; } else { $post['filelist'] = array(); } $post['classname'] = 'post'; } function comment_format_message(&$val) { global $conf; if (empty($val)) return; // 使用云储存 if (1 == $conf['attach_on'] && 1 == $val['attach_on']) { $val['message'] = str_replace('="upload/', '="' . file_path($val['attach_on']), $val['message']); } elseif (2 == $conf['attach_on'] && 2 == $val['attach_on']) { // 使用图床 list($attachlist, $imagelist, $filelist) = well_attach_find_by_tid($val['tid']); foreach ($imagelist as $key => $attach) { $url = $conf['upload_url'] . 'website_attach/' . $attach['filename']; // 替换成图床 $val['message'] = FALSE !== strpos($val['message'], $url) && $attach['image_url'] ? str_replace($url, $attach['image_url'], $val['message']) : $val['message']; } } else { $val['message'] = str_replace('="upload/', '="' . file_path($val['attach_on']), $val['message']); } //$val['message'] = stripslashes(htmlspecialchars_decode($val['message'])); } // 把内容中使用了云储存的附件链接替换掉 function comment_message_replace_url($pid, $message) { global $conf; if (0 == $conf['attach_on']) { $message = FALSE !== strpos($message, '="../upload/') ? str_replace('="../upload/', '="upload/', $message) : $message; $message = FALSE !== strpos($message, '="/upload/') ? str_replace('="/upload/', '="upload/', $message) : $message; } elseif (1 == $conf['attach_on']) { // 使用云储存 $message = str_replace('="' . $conf['cloud_url'] . 'upload/', '="upload/', $message); } elseif (2 == $conf['attach_on']) { // 使用图床 评论使用图床,mysql会过多,写死链接到内容是减轻mysql的过多的方法 list($attachlist, $imagelist, $filelist) = well_attach_find_by_pid($pid); foreach ($imagelist as $key => $attach) { $url = $conf['upload_url'] . 'website_attach/' . $attach['filename']; // 替换回相对链接 $message = $attach['image_url'] && FALSE !== strpos($message, $attach['image_url']) ? str_replace($attach['image_url'], $url, $message) : $message; } } return $message; } function comment_filter($val) { unset($val['userip']); return $val; } function comment_highlight_keyword($str, $k) { $r = str_ireplace($k, '' . $k . '', $str); return $r; } // //
function comment_message_format(&$s) { if (xn_strlen($s) < 100) return; $s = preg_replace('#.*?
#is', '', $s); $s = str_ireplace(array('
', '
', '
', '

', '', '', '', '' . ''), "\r\n", $s); $s = str_ireplace(array(' '), " ", $s); $s = strip_tags($s); $s = preg_replace('#[\r\n]+#', "\n", $s); $s = xn_substr(trim($s), 0, 100); $s = str_replace("\n", '
', $s); } // 对内容进行引用 function comment_quote($quotepid) { $quotepost = comment_read($quotepid); if (empty($quotepost)) return ''; $uid = $quotepost['uid']; $s = $quotepost['message']; $s = comment_brief($s, 100); $userhref = url('user-' . $uid); $user = user_read_cache($uid); $r = '
' . $user['username'] . ' ' . $s . '
'; return $r; } // 获取内容的简介 0: html, 1: txt; 2: markdown; 3: ubb function comment_brief($s, $len = 100) { $s = strip_tags($s); $s = htmlspecialchars($s); $more = xn_strlen($s) > $len ? ' ... ' : ''; $s = xn_substr($s, 0, $len) . $more; return $s; } ?>【如何学习python自动化测试】—— 浏览器驱动的安装 以及 如何更新driver
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

【如何学习python自动化测试】—— 浏览器驱动的安装 以及 如何更新driver

运维笔记admin41浏览0评论

🌟欢迎来到 我的博客 —— 探索技术的无限可能!


🌟博客的简介(文章目录)

【如何学习Python自动化测试】系列文章目录

1.自动化测试环境搭建
  (补充)浏览器驱动的安装 以及 如何更新driver
2.页面元素定位
3.时间等待
4.浏览器操作
5.鼠标键盘操作
6.多层窗口定位
7.警告框处理
8.Cookie 处理
9.expected_conditions
10.Python 的 unittest 框架
11.HTMLTestRunner 生成测试报告


      之前讲到基于python的自动化测试环境,需要安装Python,再安装Selenium。具体可看【如何学习Python自动化测试】—— 自动化测试环境搭建
      但是,想要使用Selenium发送指令模拟人类行为操作浏览器,就需要安装浏览器驱动。不同的浏览器需要安装各自的驱动。
      具体步骤(chrome举例): 可直接跳转至本文【3.Chrome浏览器驱动器chromedriver的安装】。

1. Python的安装和配置

      验证Python是否安装成功

2.Selenium的安装和配置

(1) 安装selenium

      在命令行窗口输入 pip install selenium命令安装selenium

(2)验证selenium是否安装成功

      在命令行窗口输入 pip show selenium验证selenium安装是否成功。

3.Chrome浏览器驱动器chromedriver的安装

(1)查看Chrome版本

       从Chrome浏览器右上角的菜单中选择【关于Google Chrome(G)】,查看浏览器的版本,从而得出自己机器上Chrome的版本。

(2)下载chromedriver.exe

Chrome 115之前的版本

       可以从https://chromedriver.storage.gooleeapis/index.html下载,如果访问失败,可以使用淘宝镜像地址:https://npm.taobao/mirrors/chromedriver/。选择对应的版本号进入,如果没有对应的,就选择最相近的版本号。然后根据自己的系统选择对应的zip文件进行下载。如系统是win32,就选择chromedriver_win32.zip。


       如图:因为由(1)查看Chrome版本可知现在我的Chrome的版本为110.0.5481.178,最近的chromedriver版本号为110.0.5481.77,我的电脑为window(64位),选择chromedriver_win32.zip。



更新driver

      Google Chrome经常会自动更新版本,可能你前段时间还是版本a,现在再次看会发现Chrome已是最新版本b。在这个时候运行一个web自动化测试脚本时,报了如下的错误,Message: session not created: This version of ChromeDriver only supports Chrome version 110
      意思就是: 你的ChromeDriver(Chrome驱动器)版本只能维持 Chrome(谷歌浏览器)110版本的,而我当前的Chrome 版本是 113.0.5672.64,路径***** 。

这个问题的解决办法也很简单,有两种办法:
      第一种:换浏览器(别的浏览器可能还未更新)
      第二钟:换ChromeDirver驱动,安装新的ChromeDirver驱动,具体步骤:(1)查看Chrome版本(2)下载chromedriver.exe(3)打开chromedriver.exe存放位置,将新的chromedriver.exe代替旧的chromedriver.exe。


Chrome 115之后的版本

      和之前一样的报错Message: session not created: This version of ChromeDriver only supports Chrome version 113 Current browser version is 119.0.6045.160 with binary该报错提示,当前的driver只支持113版本的Chrome浏览器,但是我的Chrome已经自动更新到119版本了,我们要想运行脚本,就要更新driver,把driver更新到119。
      但是,当访问了之前下载镜像的网站,结果发现没有119版本的driver可以下载,最多只到114版本,如下图:

      去官网上进行查看:chromedriver官网

      官网发了新的通知,并给了新的Chromedriver下载地址Chromedriver下载地址,我们可以在这个网址下载对应版本的Chromedriver,如下图:

      复制链接直接下载即可,下载完成之后,解压拖入之前driver所在的文件夹即可使用,完成之后,再次运行脚本,运行即恢复正常。



(3)配置环境

      下载完成了,将chromedriver.exe的路径添加到环境变量Path中。

      chromedriver.exe存放位置:

(4)使用WebDriver

      打开命令行窗口,依次执行下面操作:
            (1) 输入“python”


            (2) 输入“from selenium import webdriver”


            (3) 输入“driver = webdriver.Chrome()”


            (4) 输入“driver.get(“https://www.baidu”)”

            (5) 输入“driver.quit()”退出浏览器


      上面一系列的操作,可以验证chromedriver和所使用的浏览器版本是否匹配,是否安装成功。


浏览器驱动

1.Chrome

115之前的版本:

  • Chrome浏览器驱动chromedriver驱动官方

  • 淘宝镜像地址

115之后的版本 :

  • Chromedriver下载地址
  • 谷歌历史版本

2.IE

  • IE浏览器驱动IEDriverServer

3.Edge

  • Edge浏览器驱动MicrosoftWebDriver

4.Firefox

  • 火狐浏览器历史版本

  • geckodriver驱动

5.Opera

  • Opera浏览器驱动operadriver
发布评论

评论列表(0)

  1. 暂无评论