selenium+python笔记8
Posted 七月的尾巴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium+python笔记8相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ import unittest import os import time from selenium import webdriver class TestConfigFirefox(unittest.TestCase): def setUp(self): fp = webdriver.FirefoxProfile() # 在Firefox地址栏中输入about:config,查看相关配置属性 fp.set_preference("browser.download.folderList", 2) fp.set_preference("browser.download.manager.showWhenStarting", False) fp.set_preference("browser.download.dir", os.getcwd()) fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream") # 下载文件的类型 self.driver = webdriver.Firefox(firefox_profile=fp) self.driver.maximize_window() self.driver.implicitly_wait(30) self.base_url = "http://www.baidu.com" self.verificationErrors = [] def test_baidu(self): driver = self.driver driver.get(self.base_url + "/") driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys("unittest") driver.find_element_by_id("su").click() time.sleep(2) title = driver.title self.assertEqual(title, u"unittest_百度搜索") def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors) if __name__ == "__main__": unittest.main()
以上是关于selenium+python笔记8的主要内容,如果未能解决你的问题,请参考以下文章
Selenium Xpath元素无法定位 NoSuchElementException: Message: no such element: Unable to locate element(代码片段