通过Selenium库可以使用python代码对于浏览器进行控制,测试脚本执行时,浏览器自动按照脚本代码做出点击,输入,打开,验证等操作,就像真实用户所做的一样,从终端用户的角度测试应用程序。
Through the Selenium library, the browser can be controlled using the python code to test the script execution, and the browser automatically clicks, inputs, opens, authenticates, etc. to test the application from the end user's point of view, as is done by the real user.
这里先介绍一下最基础的访问网页,首先引用Selenium库中的webdriver,在这之前我们需要对应浏览器的驱动,可以在github下载,除此以外浏览器本体也需要下载,否则运行下列程序会报错。
The most basic access pages are described here, starting with Webdriver in the Selenium library, before which we need to match the browser driver, which can be downloaded in github, in addition to which the browser's body also needs to be downloaded, or the following program will be wrongly run.
from selenium import webdriver browser = webdriver.Chrome() browser.get("https://www.baidu.com/")
至此我们实现了模拟用户启动chrome浏览器访问指定网页的功能。
To this end, we have implemented the simulation of the start-up of the chrome browser to access the designated web page.
后续会使用更多的网页操作功能来完成更加复杂的任务。
This will be followed by the use of more web-based operating features to carry out more complex tasks.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论