selenium+python脚本编写笔记(四)

本文介绍了如何使用Selenium进行自动化测试,包括PAC代理的设置、不同浏览器驱动(如Internet Explorer、Chrome和Firefox)的版本对应与下载来源。还提到了火狐和IE在文件上传时的差异,以及在域安全控制系统中使用Selenium可能遇到的登录问题和解决策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
  • PAC代理
代理上网的服务器测试,如果在浏览器上配置代理,会导致selenium报错,可以采用PAC代理方式解决:
编写如下文件,存储城proxy.pac格式
function FindProxyForURL(url, host) {
    // our local URLs from the domains below example.com don't need a proxy:
    if (shExpMatch(host, "*.example.com"))
    {
        return "DIRECT";
    }
 
    // URLs within this network are accessed through
    // port 8080 on fastproxy.example.com:
    if (isInNet(host, "10.0.0.0", "255.255.248.0"))
    {
        return "PROXY 10.228.1.130:8080";
    }
 
    // All other requests go through port 8080 of proxy.example.com.
    // should that fail to respond, go directly to the WWW:
    return "PROXY 10.228.1.130:8080; DIRECT";
}
在intenet选项,局域网-自动配置-使用自动配置脚本
参考
 
  • 浏览器驱动版本对应

Selenium Driver Collection

Internet Explorer: 
http://selenium-release.storage.googleapis.com/index.html

http://surenpi.com/2017/02/23/iedriver/
Google Chrome:
http://npm.taobao.org/mirrors/chromedriver
Mozilla Firefox:
https://github.com/mozilla/geckodriver/releases

http://blog.youkuaiyun.com/wyqlxy/article/details/50605342

 

 

  • 关于火狐与IE在文件上传时的区别

driver.find_element_by_id("MainContent_FileUpload1").click()
 #通过autoIt工具
 os.system("D:\\upload.exe")
 #通过input标签实现的上传页面,可以通过send_keys操作实现上传
  #driver.find_element_by_id("MainContent_FileUpload1").send_keys('D:\\upload_file.txt')
 
 
  • 使用本地配置启动火狐
profileDir = "C:Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xe5qiy45.default"
 profile = webdriver.FirefoxProfile(profileDir)
  • 域安全控制系统的登陆
登陆系统前要求windos安全认证
IE windows安全认证(账号密码)
通过autoit
但是火狐跟谷歌浏览器,是浏览器弹出框而非windows框,使用浏览器的alert框认证,需要用cookie记住账号密码(profileDir = "C:Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xe5qiy45.default"),然后接受alert弹框
alert = driver.switch_to_alert()
sleep(3)
 alert.accept()
  • IE系统点击没有反应
在电脑上通过IE浏览器打开系统,登陆成功后点击操作没有反应(好像是认为网站有风险,把网站数据屏蔽了之类的),提示数据保护之类的,此时 先把ie恢复默认设置后,点击就有反映了,然后再根据selenium的要求配置下ie即可
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值