python 爬虫selenium自动化点击

import time
import unittest

from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FOptions


class AutoTest(unittest.TestCase):

    def setUp(self):
        options = FOptions()
        self.browser = webdriver.Firefox(executable_path="D:/geckodriver.exe",firefox_options=options)
        # self.browser.maximize_window()

    def tearDown(self):
        # self.brower.close()
        pass

    def test_login(self):
        self.browser.maximize_window()
        self.browser.get('http://example.webscraping.com/places/default/user/login?_next=/places/default/index')
        self.browser.find_element_by_id('auth_user_email').send_keys('186****[email protected]')
        self.browser.find_element_by_id('auth_user_password').send_keys('***')
        self.browser.find_element_by_css_selector('input.btn').click()

    def test_search(self):
        self.browser.maximize_window()
        self.browser.get('http://example.webscraping.com/places/default/search')
        self.browser.find_element_by_id('search_term').send_keys('china')
        self.browser.find_element_by_id('search').click()
        time.sleep(3)
        result = self.browser.find_element_by_xpath('//div/a[@href="/places/default/view/China-47"]')
        self.browser.find_element_by_css_selector('div#results a')
        self.assertIsNotNone(result)
        self.assertEquals(result.text,'China')

你可能感兴趣的:(python)