如何搭建python+selenium自动化环境(python,selenium,开发技术)

时间:2024-05-04 22:29:36 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

第一步:安装python解释器

自动化测试最好下载3.7的。

如何搭建python+selenium自动化环境

下载完成后打开这个文件,然后傻瓜式安装。

如何搭建python+selenium自动化环境

如何搭建python+selenium自动化环境

安装好后,win+r打开命令行窗口,输入python。如果显示下图,就说明安装成功。

如何搭建python+selenium自动化环境

第二步:安装pycharm编译器。

傻瓜式安装就可以了。

如何搭建python+selenium自动化环境

第三步:安装selenium库

pipinstallselenium

如何搭建python+selenium自动化环境

第四步:下载浏览器的驱动

我一般用的都是chrome比较具有代表性。

下载好后,将驱动放在python文件夹的scripts根目录中。

第五步:打开pycharm写第一个自动化demo验证环境是否有问题

第一个demo

fromseleniumimportwebdriverimporttimeimportunittestclassLoginPage(object):driver=webdriver.Firefox()driver.get("https://passport.hupu.com/pc/login?project=nba&from=pc")time.sleep(5)deftest_login(self):self.driver.find_element_by_xpath("//*[@id='J_username']").click()self.driver.find_element_by_xpath("//*[@id='J_username']").clear()self.driver.find_element_by_xpath("//*[@id='J_username']").send_keys("18777777777")self.driver.find_element_by_xpath("//*[@id='J_pwd']").click()self.driver.find_element_by_xpath("//*[@id='J_pwd']").clear()self.driver.find_element_by_xpath("//*[@id='J_pwd']").send_keys("111111111")self.driver.find_element_by_xpath("//*[@id='SM_BTN_1']/div[1]/div[4]").click()time.sleep(6)deftest_threads(self):self.driver.get("https://bbs.hupu.com/hcbig")time.sleep(6)self.driver.find_element_by_id("g_n").click()time.sleep(6)self.driver.find_element_by_id("atc_title").click()self.driver.find_element_by_id("atc_title").clear()self.driver.find_element_by_id("atc_title").send_keys("橙子发的文字贴")self.driver.find_element_by_xpath("//body").click()self.driver.find_element_by_xpath("//body").send_keys("橙子使用自动化测试发的文字贴")self.driver.find_element_by_id("submitview").click()login=LoginPage()login.login()time.sleep(4)login.fatie_4524()

只要能启动成功启动浏览器,并且能看到鼠标自动操作,就代表环境没有问题了。

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:如何搭建python+selenium自动化环境的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:C语言如何实现队列下一篇:

3 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18