selenium示例

#!/usr/bin/env python3
# @Time    : 2017/12/21 11:06
# @Author  : RUANBINBIN
# @Site    : 
# @File    : baletu.py
# @Software: PyCharm

from selenium import webdriver
from selenium.webdriver.common.action_chains import *
import time


def find_nav(driver):
    nav = driver.find_element_by_xpath("/html/body/div[1]/div/div[2]/a")
    ActionChains(driver).move_to_element(nav).perform()

chrome = webdriver.Chrome()
url_sh = 'http://sh.baletu.com'

chrome.get(url_sh)
time.sleep(5)
find_nav(chrome)
bj = chrome.find_element_by_link_text("北京")

bj.click()


time.sleep(5)
find_nav(chrome)
sz = chrome.find_element_by_link_text("深圳")
bj.click()

chrome.quit()

你可能感兴趣的:(selenium)