Selenium(Python)驱动Chrome浏览器
Chrome浏览器与chromedriver.exe驱动可以是官网上最新的,
随意!
Chrome.py:
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait options = webdriver.ChromeOptions()
options.add_argument("disable-infobars")
driver = webdriver.Chrome(chrome_options=options)
# 消除“Chrome正受到自动测试软件的控制”提示 driver.get("https://www.baidu.com")
# 打开百度首页
driver.maximize_window()
# 把浏览器窗口最大化
WebDriverWait(driver, 15).until(lambda x: x.find_element_by_xpath(".//*[@id='kw']"))
# 等待搜索框出现 driver.find_element_by_xpath(".//*[@id='kw']").send_keys("中国")
# 输入中国
driver.find_element_by_xpath(".//*[@id='su']").click()
# 点击搜索按钮
WebDriverWait(driver, 15).until(lambda x: x.find_element_by_xpath(".//*[@id='1']/h3/a"))
# 等待中国_百度百科元素加载 driver.close()
# 关闭浏览器窗口
driver.quit()
# 结束
Selenium(Python)驱动Chrome浏览器的更多相关文章
- Selenium+Python调Chrome浏览器时报Traceback (most recent call last): File "C:/Users/EDZ/Desktop/selenium_demo/demo001.py", line 12, in <module>
上次使用Selenium+Python还是好几个月前了 今天想再用一下,结果写个打开网站的小demo报错,报错如下: 检查了一下,查看报错日志,应该是chrome版本和driver版本不一致导致的. ...
- selenium驱动chrome浏览器问题
selenium是一个浏览器自动化测试框架,以下介绍其如何驱动chrome浏览器? 1.下载与本地chrome版本对应的chromedriver.exe ,下载地址为http://npm.taobao ...
- selenium webdriver启动Chrome浏览器后无法输入网址的解决办法
通过selenium webdriver启动Chrome浏览器,脚本如下: from selenium import webdriver browser = webdriver.Chrome() br ...
- Selenium驱动Chrome浏览器
import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome ...
- 爬虫动态渲染页面爬取之selenium驱动chrome浏览器的使用
Selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样,可以用其进行网页动态渲染页面的爬取. 支持的浏览器包括IE(7, 8, 9, 10 ...
- (原创)如何使用selenium 驱动chrome浏览器并且打开方式为手机模式-转载请注明出处
随着移动设备使用率的不断增加,移动页面的测试也变得越来越重要. 对于互联网公司M站的测试,如果不通过专用的appium等移动端测试工具是否还有方便快捷的办法呢?答案当然是有啊. 使用chrome dr ...
- selenium python 启动Chrome
启动Chrom浏览器 下载chromedriver: http://chromedriver.storage.googleapis.com/index.html 当时找chromedriver与chr ...
- selenium+python自动化87-Chrome浏览器静默模式启动(headless)
前言 selenium+phantomjs可以打开无界面的浏览器,实现静默模式启动浏览器完成自动化测试,这个模式是极好的,不需要占用电脑的屏幕. 但是呢,phantomjs这个坑还是比较多的,并且遇到 ...
- python3.6中使用selenium + chromedriver访问Chrome浏览器时报错
from selenium import webdriver from selenium.webdriver.chrome.options import Options if __name__ == ...
随机推荐
- event对象,ie8及其以下
event 对象是 JavaScript 中一个非常重要的对象,用来表示当前事件.event 对象的属性和方法包含了当前事件的状态.当前事件,是指正在发生的事件:状态,是与事件有关的性质,如引发事件的 ...
- Vue.js-简单的增删查功能
1.Vue.js是什么? Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图 ...
- 十八、IntelliJ IDEA 常用快捷键 之 Windows 版
IntelliJ IDEA(简称 IDEA),是 Java 语言开发的集成环境,IDEA 在业界被公认为最好的 Java 开发工具之一,尤其在智能代码助手.代码自动提示.重构.J2EE 支持.各类版本 ...
- Spring使用java代码配置Web.xml进行访问service
方式一:继承WebMvcConfigurerAdapter类 1.使用一个类来继承 package com.wbg.springJavaConfig.spring; import org.spring ...
- requireJS使用教程
一:为什么要使用requireJS? 很久之前,我们所有的JS文件写到一个js文件里面去进行加载,但是当业务越来越复杂的时候,需要分成多个JS文件进行加载,比如在页面中head内分别引入a.js,b. ...
- Many-to-many relationships in EF Core 2.0 – Part 4: A more general abstraction
In the last few posts we saw how to hide use of the join entity from two entities with a many-to-man ...
- linux常用监测命令
1 uptime uptime 命令可以用来查看服务器已经运行了多久,当前登录的用户有多少. 2 top top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于W ...
- hdu_4135_Co-prime
Given a number N, you are asked to count the number of integers between A and B inclusive which are ...
- MySQL学习之用户管理
用户权限管理 用户权限管理:在不同的项目中给不同的角色(开发者)不同的操作权限,为了保证数据库数据的安全. 简单点说:有的用户可以访问并修改这个数据,而有些用户只能去查看数据,而不能修改数据.就如同博 ...
- Linux查看MAC地址方法
注:一般默认的网卡文件名是eth0,根据IP地址对应的实际情况区判断是ethx即可. 1. ip -a . cat /sys/class/net/ens39/address 其中 HWaddr字段就 ...